Git Cherry-Pick Explained: Copy One Commit to Another Branch
git cherry-pick copies a specific commit from one branch onto another — handy for getting a bug fix into production without merging everything else. How to use it, picking ranges, handling conflicts, and when a merge is the better choice.
You fixed a bug on your feature branch. The fix needs to go to production now, but the rest of the feature isn't ready. You don't want to merge the whole branch — you want just that one commit.
That's what git cherry-pick does: it copies a commit from anywhere in your repository and applies it on top of your current branch.
The basic use
- Find the commit's hash:
git log --oneline feature/search
9e8f7a6 Add search filters UI
4b5c6d7 Fix crash when cart is empty ← this one
1a2b3c4 Start search feature
- Switch to the branch that needs it, and pick it:
git switch main
git cherry-pick 4b5c6d7
Git creates a new commit on main with the same changes and message. It has a different hash, because it has a different parent — it's a copy, not a move. The original stays on the feature branch.
Picking several commits
git cherry-pick 4b5c6d7 8d9e0f1 # specific commits, in order
git cherry-pick 1a2b3c4^..9e8f7a6 # a range, including 1a2b3c4
(A..B excludes A; A^..B includes it.)
Useful options
| Option | Does |
|---|---|
-x |
Adds "(cherry picked from commit …)" to the message — helps track where it came from |
-n / --no-commit |
Applies the changes but doesn't commit, so you can combine or edit |
-e |
Lets you edit the commit message |
For hotfixes, -x is a nice habit: later, anyone can see that the fix on main came from the feature branch.
When there's a conflict
If the commit touches code that's different on your branch, git stops:
error: could not apply 4b5c6d7... Fix crash when cart is empty
hint: after resolving the conflicts, mark the corrected paths
Resolve the conflict markers in the files (merge conflicts explained), then:
git add .
git cherry-pick --continue
Or give up and return to how things were:
git cherry-pick --abort
When to cherry-pick
- Hotfixes: a fix made on one branch needs to reach production or a release branch.
- Backports: a fix needs to go into an older supported version.
- Rescuing a commit made on the wrong branch (pick it onto the right one, then remove it from the wrong one).
- Salvaging one good commit from an abandoned branch or an AI agent's experiment.
When not to
Cherry-picking duplicates commits. If you cherry-pick a commit to main and later merge the feature branch too, git usually handles it — but you can get confusing conflicts, and history shows the same change twice.
If you want most of a branch, merge it. If you want a fix to be in both branches long-term, a common pattern is to make the fix on main first (or its own small branch merged into main), then merge or rebase the feature branch onto main so it picks up the fix naturally.
Use cherry-pick for the exceptions, not as your main workflow. (Git rebase vs merge)
Cherry-picking from an AI agent's branch
If you run AI agents on separate branches or worktrees, cherry-pick is a clean way to take the one commit that worked from an attempt that otherwise went sideways. Agents that make small, focused commits make this much easier — worth asking for. (Write good commit messages, parallel agents with worktrees)
The summary
git cherry-pick <hash>copies one commit onto your current branch.- Use
-xto record where it came from. - Resolve conflicts, then
--continue; or--abort. - Great for hotfixes and rescues; merge when you want most of a branch.
EasySpawn keeps your repository and every agent branch on a persistent server, so you can review what Claude Code did and pick exactly the commits you want. See how it works or join the waitlist.
Related: Git Branches Explained · Git Rebase vs Merge · How to Undo Almost Anything in Git · Git Detached HEAD Explained
Keep reading
What Is WSL? Running Linux on Windows, Explained
WSL lets you run a real Linux system inside Windows without dual-booting or a separate virtual machine to manage. What it is, why web developers use it, how to install it, where your files live, and the performance and networking gotchas.
What Is an IDE? Code Editors vs IDEs Explained
An IDE (integrated development environment) puts everything you need to write software in one app: editor, file browser, terminal, debugger, git and more. How it differs from a plain code editor, the popular options, cloud IDEs, and where AI fits in.