🍒 Need One Commit from Another Branch?
Merge brings all commits. Sometimes you need just one. Cherry-pick applies specific commits to current branch.
📝 Basic Cherry-Pick
# Switch to target branch git checkout main # Cherry-pick a commit from feature branch git cherry-pick a1b2c3d # Cherry-pick multiple commits git cherry-pick a1b2c3d d4e5f6g g7h8i9j # Cherry-pick range git cherry-pick a1b2c3d..g7h8i9j # Cherry-pick from another repository git fetch ../other-repo feature git cherry-pick FETCH_HEAD
🎯 Real-World Scenarios
# Hotfix applied to feature branch, need on main git checkout main git cherry-pick hotfix-commit # Backport feature to older version git checkout v1.0 git cherry-pick new-feature-commit # Fix conflict during cherry-pick git cherry-pick abc123 # resolve conflicts git add . git cherry-pick --continue # Abort cherry-pick git cherry-pick --abort # Cherry-pick without committing (stage only) git cherry-pick -n abc123
💡 When to Use Cherry-Pick
- Hotfix needs to go to multiple branches
- Backporting features to older versions
- Selective commits from feature branch (not ready for full merge)
- Moving a commit that was made on wrong branch
“Bug fix committed to develop, needed on main. Cherry-picked the one commit. No merge, no extra commits. Clean and precise.”
