Git Version Control
Git adalah version control system yang essential untuk software development.
Instalasi Git
Linux
sudo apt install git
macOS
brew install git
Windows
Download dari https://git-scm.com/
Konfigurasi Awal
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Dasar Git Commands
# Inisialisasi
git init
# Clone repository
git clone https://github.com/user/repo.git
# Cek status
git status
# Stage files
git add .
git add filename.txt
# Commit
git commit -m "Initial commit"
# Lihat log
git log
git log --oneline
Branching
# Buat branch baru
git branch feature/login
# Switch branch
git checkout feature/login
# Atau dalam satu command
git checkout -b feature/login
# Hapus branch
git branch -d feature/login
Merging
# Di branch main
git checkout main
# Merge feature branch
git merge feature/login
Remote Operations
# Tambah remote
git remote add origin https://github.com/user/repo.git
# Push ke remote
git push origin main
# Pull dari remote
git pull origin main
Git Workflow
Feature Branch Workflow
main (production)
↑
|
develop
↑
|
feature/login
Pull Request
- Buat feature branch
- Push ke remote
- Buat Pull Request di GitHub/GitLab
- Review dan merge
Troubleshooting
Undo last commit
# Soft reset (hapus commit tapi keep changes)
git reset --soft HEAD~1
# Hard reset (hapus commit dan discard changes)
git reset --hard HEAD~1
Stash Changes
# Simpan sementara
git stash
# Restore stash
git stash pop
Best Practices
- Commit frequently - Small, frequent commits
- Write good commit messages - Conventional Commits
- Use .gitignore - Exclude unnecessary files
- Pull before push - Avoid conflicts
- Review changes before commit - git diff
Conventional Commits
feat: add user authentication
fix: fix login bug
docs: update README
style: format code
refactor: simplify auth logic
test: add user tests
chore: update dependencies