Cherry Picking
Apply specific commits from one branch to another.
What is Cherry Pick?
Cherry pick takes a commit from one branch and applies it to another, without merging the entire branch.
Before:
main: A---B---C
\
feature: D---E---F
Cherry pick E to main:
main: A---B---C---E'
\
feature: D---E---F
Basic Cherry Pick
Cherry Pick Commands
| Command | Description |
|---|---|
git cherry-pick <commit> | Apply commit |
git cherry-pick -n <commit> | Apply without committing |
git cherry-pick --continue | Continue after conflict |
git cherry-pick --abort | Cancel cherry pick |
Single Commit
git cherry-pick abc1234
Multiple Commits
# Multiple specific commits
git cherry-pick abc1234 def5678
# Range of commits
git cherry-pick abc1234..ghi9012
Cherry Pick Options
Without Auto-Commit
git cherry-pick -n abc1234
Keep Original Author
git cherry-pick -x abc1234
Adds "cherry picked from commit abc1234" to message.
Handling Conflicts
When cherry pick has conflicts:
- Resolve conflicts in files
- Stage:
git add . - Continue:
git cherry-pick --continue
Or abort:
git cherry-pick --abort
Use Cases
- Hotfix: Apply bug fix from develop to main
- Selective features: Take specific commits without merging all
- Backporting: Apply fix to older release branches
Cherry Pick Workflow
# Find commit to pick
git log --oneline feature-branch
# Switch to target branch
git checkout main
# Cherry pick the commit
git cherry-pick abc1234
Caution
Cherry picked commits get new hashes. The original and cherry picked commits are different commits with the same changes.
Exercise: Cherry Pick a Commit
Cherry pick a commit from the log:

