W3docs

git cherry-pick

Learn the git cherry-pick command to copy individual commits from one branch onto another. See options, conflict handling, and examples.

Definition

The git cherry-pick command takes the change introduced by one or more existing commits and reapplies them on your current branch as new commits. Where git merge and git rebase move whole lines of history, cherry-pick lets you grab a single commit and drop it exactly where you need it.

git cherry-pick copying a commit from a feature branch onto main

How it works

Cherry-pick computes the diff that a commit introduced relative to its parent, then applies that diff to the tip of your current branch and records a new commit. The result has the same content change but a new hash and a new parent, because it lives in a different place in history.

git switch main
git cherry-pick a1b2c3d

The change from commit a1b2c3d is now on main as a fresh commit.

Picking a range of commits

You can apply several commits at once. A range copies every commit after the first up to and including the last:

git cherry-pick a1b2c3d^..f4e5d6c

The ^ on the first reference makes the range inclusive of that starting commit.

Common options

CommandDescription
git cherry-pick <commit>Applies the change from <commit> as a new commit on the current branch.
git cherry-pick -n <commit>Applies the change but does not commit, leaving it staged for review.
git cherry-pick -x <commit>Records a line noting which commit was cherry-picked (useful for public branches).
git cherry-pick -e <commit>Lets you edit the commit message before committing.
git cherry-pick --continueResumes after you have resolved conflicts.
git cherry-pick --abortCancels the operation and restores the original state.

Handling conflicts

If the change does not apply cleanly, cherry-pick pauses much like a merge does. Resolve the conflicted files, stage them with git add, and continue:

git cherry-pick --continue

If you would rather back out entirely, run git cherry-pick --abort to return the branch to where it started.

When to use it

Cherry-pick shines when a fix landed on the wrong branch, when you need to backport a single patch to a release branch, or when you want one commit from a feature without merging the whole thing. Use it sparingly on shared history — copying commits creates duplicates that can complicate later merges.

Practice

Practice

What does 'git cherry-pick' do with the commit it copies?