Elena' s AI Blog

Git Cherry-Pick: The Surgeon's Knife

20 Feb 2026 (updated: 17 Jul 2026) / 5 minutes to read

Elena Daehnhardt


Precision Operation, Midjourney 2026


TL;DR:
  • Need just one specific commit from another branch? Don't merge the whole thing. Use 'git cherry-pick' to surgically apply changes where you need them.

Previous: Part 29 — Type Less, Do More: My Top 10 Git Aliases

Next: Part 31 — Testing Blog Designs with Git Branches and GitHub Pages

Git is usually about managing streams of history. You merge rivers of code together. But sometimes, you don’t want the whole river. You just want one specific fish.

That’s git cherry-pick.

What Is Git Cherry-Pick?

Git cherry-pick is a Git command that takes the changes from a single specified commit and applies them to the current branch as a new commit, without merging the rest of that commit’s branch history.

Git cherry-pick is highly useful in specific scenarios:

  1. Hotfixes: You fixed a bug in dev, and you need that same fix in prod right now, but you can’t merge dev yet because it has unfinished features.
  2. Mistakes: You committed to the wrong branch.

How to Use Git Cherry-Pick: Step-by-Step Workflow

Let’s say you are on main and you want commit abc1234 that exists on feature-branch.

  1. Find the hash:
    git log feature-branch
    # verify that abc1234 is the one you want
    
  2. Execute the pick:
    git checkout main
    git cherry-pick abc1234
    

Git takes the diff from that commit and tries to apply it to main. If successful, it automatically creates a new commit with a new SHA — the content matches the original commit, but the commit hash does not.

Resolving Git Cherry-Pick Conflicts

Just like a merge, cherry-picking can result in conflicts if the code has diverged too much. When this happens, Git pauses and prints an error similar to:

error: could not apply abc1234... <commit message>
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

Error: could not apply <hash>... <message>

Cause: the cherry-picked commit’s diff conflicts with changes already on the current branch.

Fix:

  1. Open the conflicted files and resolve the <<<<<<<, =======, and >>>>>>> conflict markers.
  2. git add <file>
  3. git cherry-pick --continue

If you want to cancel the operation entirely instead, run git cherry-pick --abort to return the branch to its pre-pick state.

Error: The previous cherry-pick is now empty

Cause: the changes from the picked commit are already present on the current branch (often after manual conflict resolution), so Git has nothing left to commit.

Fix: run git cherry-pick --skip to move past the empty commit, or git commit --allow-empty if you specifically want to preserve it as a marker in history.

When Not to Use Git Cherry-Pick: Merge and Rebase Alternatives

Don’t use cherry-picking as a substitute for proper merging. If you find yourself cherry-picking 10 commits in a row, you are probably doing it wrong—you should likely be merging or rebasing instead.

Cherry-picking creates duplicate commits (different SHA hashes, same content diff). If you later merge the branches, Git is usually smart enough to figure it out, but it creates a messy history. Use cherry-pick sparingly.

Git Cherry-Pick: Definitive Use Case Summary

Git cherry-pick represents a precision-application technique that copies a single commit’s diff onto another branch without importing that branch’s full history. You won’t use it every day, but when you need to extract a critical fix without bringing in unwanted baggage, it is the tool for the job.

See the official Git documentation on cherry-pick for the complete flag reference (--no-commit, -x, -m).

Git Cherry-Pick FAQ

What does git cherry-pick do?

Git cherry-pick takes the changes introduced by a single specified commit and applies them to the current branch as a new commit with a new SHA, without merging the rest of that commit’s branch history.

How is git cherry-pick different from git merge?

git merge brings in the full history of another branch, while git cherry-pick applies only one specific commit’s diff, leaving the rest of the source branch’s history untouched.

Can I cherry-pick multiple commits at once?

Yes. Pass a range or a list of hashes, for example git cherry-pick abc1234 def5678, or a range like git cherry-pick abc1234^..def5678 to apply a contiguous sequence of commits.

What happens if git cherry-pick hits a conflict?

Git pauses the operation and reports error: could not apply <hash>... <message>. Resolve the conflict markers in the affected files, stage them with git add, then run git cherry-pick --continue (or git cherry-pick --abort to cancel).

How do I cancel a cherry-pick in progress?

Run git cherry-pick --abort to stop the operation and return the branch to the state it was in before the cherry-pick started.

Did you like this post? Please let me know if you have any comments or suggestions.

Git posts that might be interesting for you




desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.



Citation
Elena Daehnhardt. (2026) 'Git Cherry-Pick: The Surgeon's Knife', daehnhardt.com, 20 February 2026. Available at: https://daehnhardt.com/blog/2026/02/20/git-cherry-pick/
All Posts