Skip to content

git cherry-pick

cherry-pick applies a specific commit (or range of commits) to the current branch, creating a new commit with the same changes but a different hash.

Terminal window
# Apply a specific commit to the current branch
git cherry-pick abc1234
# Apply multiple commits
git cherry-pick abc1234 def5678
# Apply a range of commits (exclusive..inclusive)
git cherry-pick abc1234..ghi9012
Terminal window
# Bug fixed on main
git log --oneline main
# abc1234 Fix null pointer in payment processor
# ...
# Apply the fix to the v2 release branch
git switch release/v2.0
git cherry-pick abc1234

Apply a Commit That Went to the Wrong Branch

Section titled “Apply a Commit That Went to the Wrong Branch”
Terminal window
# Accidentally committed to main instead of feature branch
git log --oneline main
# def5678 Add experimental feature
# ...
# Move it to the feature branch
git switch feature/experimental
git cherry-pick def5678
# Remove from main (if it wasn't pushed yet)
git switch main
git reset --hard HEAD~1

Pull a Single Fix Without Merging an Entire Branch

Section titled “Pull a Single Fix Without Merging an Entire Branch”
Terminal window
# Colleague has a large branch with one critical fix you need now
git cherry-pick abc1234 # just the fix, not the whole branch
Terminal window
# Apply but don't commit (leave changes staged)
git cherry-pick -n abc1234
git cherry-pick --no-commit abc1234
# Cherry-pick and edit the commit message
git cherry-pick -e abc1234
# Add "cherry picked from commit..." to message
git cherry-pick -x abc1234
# Continue after resolving conflicts
git cherry-pick --continue
# Abort cherry-pick in progress
git cherry-pick --abort
# Skip a conflicting commit and continue with the rest
git cherry-pick --skip
Terminal window
git cherry-pick abc1234
# CONFLICT (content): Merge conflict in src/payment.ts
# error: could not apply abc1234...
# 1. Open the conflicting file and resolve conflicts
# 2. Stage the resolved file
git add src/payment.ts
# 3. Continue
git cherry-pick --continue

Merge commits have two parents. You must specify which parent represents the mainline:

Terminal window
git cherry-pick -m 1 abc1234 # mainline is parent 1 (usually the branch you merged into)

Cherry-pick creates a duplicate commit (same changes, different hash). If the original branch is eventually merged, you’ll have the same changes twice — which can cause confusing conflicts.

Prefer cherry-pick for:

  • Specific bug fixes needed on release branches
  • Emergency hotfixes
  • One-off commits that won’t be merged

Avoid cherry-pick when:

  • The whole feature will eventually be merged (just wait for the merge)
  • You need many commits from a branch (merge or rebase instead)
Terminal window
# See if a commit has been cherry-picked to another branch
git log --oneline main | grep "cherry picked from commit abc1234"
# Or use git log with --cherry-mark to see symmetric differences
git log --cherry-mark --oneline main...release/v2.0