πŸŽ“ Tutorial

Git & GitHub untuk Pemula: Version Control Tutorial

DevOps RJM 27 Jan 2026 4 menit 1,435 Views
Git & GitHub untuk Pemula: Version Control Tutorial

Master Version Control seperti Pro Developer

Git & GitHub adalah essential tools untuk setiap developer. Tutorial ini akan transform Anda dari zero to hero.

Apa Itu Git & GitHub?

Git:

  • Version control system
  • Track changes dalam code
  • Collaborate dengan tim
  • Revert ke previous versions

GitHub:

  • Cloud platform untuk host Git repositories
  • Collaboration features
  • Portfolio untuk developers
  • Open-source projects

Installation

Windows:

  1. Download dari git-scm.com
  2. Run installer (default settings OK)
  3. Verify: Open cmd ? git --version

Mac:

brew install git

Linux:

sudo apt-get install git

Initial Configuration

git config --global user.name "Your Name"\ngit config --global user.email "your@email.com"\ngit config --global init.defaultBranch main

Check config:

git config --list

Basic Git Workflow

1. Initialize Repository

Create new project:

mkdir my-project\ncd my-project\ngit init

Or clone existing:

git clone https://github.com/username/repo.git

2. Check Status

git status

Shows modified files, staging area, current branch

3. Stage Changes

# Stage specific file\ngit add filename.txt\n\n# Stage all changes\ngit add .\n\n# Stage all .js files\ngit add *.js

4. Commit Changes

git commit -m "Your descriptive commit message"

Good commit messages:

  • "Add login functionality"
  • "Fix navbar responsive issue"
  • "Update README with installation steps"

Bad: "update", "fix", "changes"

5. View History

# See commit history\ngit log\n\n# Compact view\ngit log --oneline\n\n# Graph view\ngit log --graph --oneline --all

Working with Branches

Why Branches?

  • Develop features independently
  • Experiment without affecting main code
  • Multiple people work simultaneously

Common Commands:

# Create new branch\ngit branch feature-name\n\n# Switch to branch\ngit checkout feature-name\n\n# Create & switch (shortcut)\ngit checkout -b feature-name\n\n# List all branches\ngit branch\n\n# Delete branch\ngit branch -d feature-name

Best Practice Branch Names:

  • feature/user-authentication
  • bugfix/login-error
  • hotfix/security-patch

Merging Branches

# Switch to main branch\ngit checkout main\n\n# Merge feature branch\ngit merge feature-name

Merge Conflicts:

Terjadi saat same line diubah di different branches

Resolution:

  1. Git akan mark conflicts di file
  2. Manually edit file, choose which changes to keep
  3. Remove conflict markers (<<<, ===, >>>)
  4. git add .
  5. git commit -m "Resolve merge conflict"

Working with GitHub

1. Create GitHub Account

github.com ? Sign up

2. Create Repository

  • Click "New repository"
  • Enter name & description
  • Public atau Private
  • Add README (optional)
  • Click "Create repository"

3. Connect Local to GitHub

# Add remote\ngit remote add origin https://github.com/username/repo.git\n\n# Push to GitHub\ngit push -u origin main

Future pushes:

git push

4. Pull Changes

# Fetch & merge changes from GitHub\ngit pull

Collaborative Workflow

Fork & Pull Request:

  1. Fork: Copy repository ke your account
  2. Clone: Download ke local
  3. Branch: Create feature branch
  4. Changes: Make modifications
  5. Commit: Commit changes
  6. Push: Push ke your fork
  7. Pull Request: Propose changes ke original repo

Useful Git Commands

Undo Changes:

# Unstage file\ngit reset filename.txt\n\n# Discard changes (CAREFUL!)\ngit checkout -- filename.txt\n\n# Undo last commit (keep changes)\ngit reset --soft HEAD~1\n\n# Undo last commit (discard changes)\ngit reset --hard HEAD~1

Stash Changes:

# Save changes temporarily\ngit stash\n\n# List stashes\ngit stash list\n\n# Apply stash\ngit stash apply\n\n# Apply & remove stash\ngit stash pop

View Differences:

# Changes not staged\ngit diff\n\n# Changes staged\ngit diff --staged\n\n# Between branches\ngit diff branch1 branch2

GitHub Features

1. README.md

Project documentation dalam Markdown

2. Issues

  • Track bugs
  • Feature requests
  • Discussion

3. Pull Requests

  • Propose changes
  • Code review
  • Discussion before merge

4. GitHub Actions

  • CI/CD automation
  • Run tests automatically
  • Deploy on push

5. GitHub Pages

  • Free website hosting
  • From repository

.gitignore File

Specify files Git should ignore

Common entries:

# Dependencies\nnode_modules/\nvendor/\n\n# Environment variables\n.env\n\n# IDE\n.vscode/\n.idea/\n\n# OS\n.DS_Store\nThumbs.db\n\n# Build\ndist/\nbuild/

Git Best Practices

  1. Commit often: Small, focused commits
  2. Descriptive messages: Explain what & why
  3. Pull before push: Avoid conflicts
  4. Branch for features: Keep main stable
  5. Review before merge: Code quality
  6. Don't commit sensitive data: Use .gitignore

Common Workflows

Daily Workflow:

# Start of day\ngit pull\n\n# Create feature branch\ngit checkout -b feature/new-thing\n\n# Make changes, then\ngit add .\ngit commit -m "Add new feature"\n\n# Push to GitHub\ngit push origin feature/new-thing\n\n# Create Pull Request on GitHub\n# After approval, merge\n\n# Switch back & update\ngit checkout main\ngit pull

Hotfix Workflow:

# From main\ngit checkout -b hotfix/critical-bug\n\n# Fix bug\ngit add .\ngit commit -m "Fix critical bug"\n\n# Push & create PR\ngit push origin hotfix/critical-bug

Troubleshooting

Forgot to branch:

# Stash changes\ngit stash\n\n# Create & switch branch\ngit checkout -b feature-branch\n\n# Apply stashed changes\ngit stash pop

Pushed wrong commit:

# Revert commit (creates new commit)\ngit revert HEAD\ngit push

Merge conflict:

# Abort merge\ngit merge --abort\n\n# Or resolve manually & commit

Learning Resources

  • Git Documentation: git-scm.com/doc
  • GitHub Learning Lab: lab.github.com
  • Interactive tutorial: learngitbranching.js.org
  • Visualize Git: git-school.github.io/visualizing-git

Kesimpulan

Git & GitHub are essential untuk modern development. Practice daily, dan soon akan jadi second nature. Happy coding!

ADVERTISEMENT
ADVERTISEMENT

Butuh Konsultasi atau Jasa Pembuatan Website?

Tim profesional kami siap membantu mewujudkan website impian Anda

Konsultasi Gratis
ο»Ώ
Hai kak! πŸ‘‹ Saya Ismail, asisten digital RJM.
Ada yang bisa saya bantu hari ini?
Ismail
Ismail
Ismail dari RJM AI
🟒 Konsultan Bisnis Digital · Partner RJM
Ismail
Halo! Saya Ismail dari RJM AI, siap membantu Anda kembangkan bisnis digital hari ini πŸš€

Yang bisa saya bantu:
β€’ Pembuatan Website & Aplikasi
β€’ SEO & Digital Marketing
β€’ Hosting, Domain & Layanan IT
β€’ Sistem ERP/HRIS (Handoo)

Ada yang bisa saya bantu?
πŸͺ

Kami Menggunakan Cookie

Website ini menggunakan cookie untuk meningkatkan pengalaman Anda, menganalisis lalu lintas situs, dan keperluan pemasaran. Dengan melanjutkan, Anda menyetujui penggunaan cookie kami sesuai Kebijakan Privasi kami.