Git Cherry Pick
Git Cherry Pick: Copying Targeted Commits Across Branches
git cherry-pick takes one or more specific commits from another branch and applies their changes as brand-new commits onto your current branch. Unlike merging an entire feature branch, cherry-picking lets you pull just one urgent bug fix onto main or a release branch without bringing unfinished features along.
Cherry-Picking a Single Commit
Suppose a developer fixed a critical header alignment bug on feature/header-nav (commit a1b2c3d), and production needs that fix immediately before the rest of the feature is ready:
git switch main
git cherry-pick -x a1b2c3d
Passing -x appends (cherry picked from commit a1b2c3d...) to the new commit message so teammates can trace where the fix originated.
Cherry-Picking Ranges or Staging Without Committing
You can apply multiple commits or stage changes without committing immediately with -n (--no-commit):
git cherry-pick a1b2c3d d4e5f6g
git cherry-pick -n a1b2c3d
To cherry-pick a contiguous range starting after A through B, use git cherry-pick A..B.
Handling Conflicts During a Cherry-Pick
If the copied commit modifies lines in styles.css that look different on main, Git pauses and inserts conflict markers. Edit styles.css to keep the clean code, stage it, and finish the cherry-pick:
git add styles.css
git cherry-pick --continue
To abandon the operation cleanly and restore your branch, run git cherry-pick --abort.
Common Cherry-Pick Mistakes
Using git cherry-pick routinely instead of merging entire branches creates duplicate commits with different SHA hashes for the same change, which can trigger confusing conflicts when the feature branch eventually merges. Reserve cherry-pick for targeted hotfixes and backports.
Frequently Asked Questions
Does git cherry-pick remove the commit from its original branch?
No. It copies the diff and creates a new commit with a new SHA hash on your current branch while leaving the original branch completely untouched.
Can I cherry-pick a merge commit?
Yes, by telling Git which parent represents the mainline using -m 1, just like git revert: git cherry-pick -m 1 <merge-hash>.
How do I edit the commit message while cherry-picking?
Pass -e (--edit)—for example git cherry-pick -e a1b2c3d—to open your editor and adjust the message before Git records the new commit.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With