Elena' s AI Blog

Git Cherry-Pick: The Surgeon's Knife

20 Feb 2026 (updated: 20 Feb 2026) / 2 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.

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.

Introduction

The command git cherry-pick <commit-hash> takes the changes from a single specific commit and applies them to your current branch as a new commit.

It’s 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 it

Let’s say you are on main and you want a 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 will take the diff from that commit and try to apply it to main. If successful, it automatically creates a commit.

Handling Conflicts

Just like a merge, cherry-picking can result in conflicts if the code has diverged too much.

If this happens, Git will pause.

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

When NOT to use it

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.

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

Conclusion

Git Cherry-pick is a precision tool. You won’t use it every day, but when you need to perform surgery on your repository—extracting a critical fix without bringing in unwanted baggage—it is the only tool for the job.

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