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:

  1. Fix bug di versi lama → branch dari commit lama, fix, terus merge back
  2. Revert fitur yang rusak → branch dari commit sebelum fitur itu di-add
  3. Experiment dengan kode lama → tidak perlu reset HEAD, langsung branch dari sana
  4. 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:

  1. git checkout -b fix-main-01 09fb6e1 # Create & switch ke branch
  2. [Edit files untuk fix bug]
  3. git add .
  4. git commit -m “fix: handle edge case”
  5. git push origin fix-main-01
  6. [Buka PR di GitHub/GitLab]