Cherry-Picking Specific Commits
7 min read
What Is Cherry-Pick?
git cherry-pick applies the changes introduced by one or more existing commits onto the current branch. Unlike a merge or rebase — which integrate an entire branch — cherry-pick is surgical: you choose exactly which commits to replay.
bash
git cherry-pick abc1234 # apply one commit
git cherry-pick abc1234 def5678 # apply multiple commits in order
git cherry-pick abc1234..ghi9012 # apply a range (exclusive start)
git cherry-pick abc1234^..ghi9012 # apply a range (inclusive start)Common Use Cases
- Backport a bugfix — a fix landed on
mainbut you need it on arelease/2.xsupport branch too. - Salvage work from a doomed branch — pick only the commits worth keeping before discarding the rest.
- Share a utility commit — a teammate wrote a helper you need without merging their entire in-progress branch.
Handling Cherry-Pick Conflicts
If the cherry-picked changes conflict with the current branch, Git pauses and marks the conflicting files just like a merge conflict. Resolve the markers, then:
bash
git add <resolved-file>
git cherry-pick --continue # finish applying the commit
# or, to abandon:
git cherry-pick --abortCherry-picking duplicates commits — the same logical change now exists in two places with different SHAs. If both branches are later merged, Git may detect the duplication, but it can also surface confusing conflicts. Use cherry-pick deliberately, not as a substitute for proper branching.
Ready to test yourself?
Practice Git & GitHub— quiz & coding exercises