Git Cherry-pick

Cherry-picking copies a single commit from one branch onto another, letting you grab exactly the change you need without merging everything else.

What cherry-pick is for

Sometimes you need one specific commit from a branch without pulling in that branch's entire history. A classic case: a bug fix was committed on a feature branch that isn't ready to ship, but the fix itself is needed on main right now. git cherry-pick takes the changes introduced by a given commit and applies them as a brand-new commit on your current branch, with a new hash but the same content.

Cherry-picking a bug fix onto main

$ git log --oneline feature/payments
a1b2c3d fix null pointer in refund calculation
9f8e7d6 add refund UI (not ready to ship)
$ git checkout main
$ git cherry-pick a1b2c3d
[main 4d5e6f7] fix null pointer in refund calculation
 Date: Thu Jul 16 09:12:03 2026 +0000
 1 file changed, 3 insertions(+), 1 deletion(-)

Cherry-picking a range of commits

You aren't limited to one commit at a time. Providing a commit range applies every commit in that range, in order. This is useful for porting a small run of related commits, though beyond two or three commits it usually signals you'd be better served by merging or rebasing the whole branch instead.

Cherry-picking a range of three commits

$ git cherry-pick a1b2c3d^..h7i8j9k
[main 4d5e6f7] fix null pointer in refund calculation
[main 8g9h0i1] add validation for refund amount
[main 2j3k4l5] add test coverage for refund edge cases
Note: Note the caret after the first hash: a1b2c3d^..h7i8j9k means 'starting from a1b2c3d itself through h7i8j9k, inclusive'. Leaving off the caret would start the range one commit later, excluding a1b2c3d.

Handling conflicts

Because the target branch has diverged from where the commit originally lived, the patch may not apply cleanly. Git pauses and marks the conflicting files exactly as it does during a merge or rebase, leaving you to resolve them by hand.

Resolving a cherry-pick conflict

$ git cherry-pick a1b2c3d
Auto-merging src/refunds.js
CONFLICT (content): Merge conflict in src/refunds.js
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' and commit the result with
hint: 'git cherry-pick --continue'
$ git add src/refunds.js
$ git cherry-pick --continue

Cherry-pick vs. merge vs. rebase

OperationScopeTypical use
cherry-pickOne or a few specific commitsPorting a hotfix to another branch
mergeEntire branch historyIntegrating a finished feature into main
rebaseEntire branch, replayed on a new baseUpdating a feature branch or cleaning history
Note: Cherry-picked commits get a new hash even though the content is identical. If that same commit later gets merged normally too, Git usually recognizes the duplicate change and skips it cleanly, but it's worth being aware the history will show the commit twice under different hashes.

Cherry-pick is a precision tool. It's excellent for backporting a fix or pulling forward one useful commit, but relying on it heavily as a substitute for regular merging tends to fragment history and make it hard to answer 'is this feature branch's work all in main yet?'

Cherry-picking without committing immediately

$ git cherry-pick -n a1b2c3d
$ git status
Changes to be committed:
  modified:   src/refunds.js
$ git commit -m "fix: null pointer in refund calculation (backport)"

Exercise: Git Cherry-pick

What does `git cherry-pick` do?