Command:
git checkout -b fix-main-01 09fb6e1
Breakdown:
- git checkout -b = Create & switch ke branch baru
- fix-main-01 = Nama branch yang dibuat
- 09fb6e1 = Commit hash sebagai starting point
Use Cases:
- Fix bug di versi lama → branch dari commit lama, fix, terus merge back
- Revert fitur yang rusak → branch dari commit sebelum fitur itu di-add
- Experiment dengan kode lama → tidak perlu reset HEAD, langsung branch dari sana
- Cherry-pick berdasarkan commit → branch dari sana, modifikasi, terus PR
Related Commands:
git checkout 09fb6e1 # Detach ke commit (no branch, temp)
git checkout -b fix-main-01 09fb6e1 # Create branch dari commit (permanent)
git branch fix-main-01 09fb6e1 # Create branch (tanpa switch)
git switch -c fix-main-01 09fb6e1 # Modern syntax (Git 2.23+)
Example Workflow:
- git checkout -b fix-main-01 09fb6e1 # Create & switch ke branch
- [Edit files untuk fix bug]
- git add .
- git commit -m “fix: handle edge case”
- git push origin fix-main-01
- [Buka PR di GitHub/GitLab]