Git Cherry-Pick Command Examples

git cherry-pick applies the changes from a specific commit onto the current branch, creating a new commit with the same changes. It is the surgical tool for porting a bug fix from one branch to another without merging the entire branch history.

GitCherry-PickVersion ControlCLI
Basic Cherry-Pick
Apply a single commit
git cherry-pick abc1234
Applies the changes introduced by commit abc1234 to the current branch and creates a new commit. The new commit has a different SHA but the same code changes and commit message. Use git log --oneline to find the commit SHA.
Apply without immediately committing
git cherry-pick --no-commit abc1234
Applies the changes to the working tree and staging area but does not create a commit. This lets you inspect or modify the changes before committing, or combine changes from multiple cherry-picks into a single commit.
Apply and edit the commit message
git cherry-pick --edit abc1234
Opens the editor to let you modify the commit message before the cherry-pick commit is created. Useful when porting a fix to a release branch and you want to add a note like "[backport]" to the message.
Pick the most recent commit from another branch
git cherry-pick feature-branch
Using a branch name instead of a SHA picks the tip (most recent commit) of that branch. This is a quick way to grab the latest commit from another branch without needing to look up its SHA.
Ranges & Multiple
Cherry-pick a range of commits
git cherry-pick abc1234^..def5678
Applies a range of commits from abc1234 (inclusive, due to ^) through def5678. Without the ^, the range starts after abc1234 (exclusive). All commits in the range are applied in order.
Cherry-pick multiple specific commits
git cherry-pick abc1234 def5678 ghi9012
List multiple commit SHAs separated by spaces to apply each one individually in the order given. Each creates a separate commit on the current branch. This is useful for selectively backporting non-consecutive commits.
Conflict Resolution
Continue after resolving a conflict
# 1. Edit conflicting files to resolve
git add resolved-file.txt
git cherry-pick --continue
When a cherry-pick hits a conflict, it pauses and shows the conflicting files. Resolve the conflicts manually, stage the resolved files, and then continue. Git will create the cherry-pick commit.
Abort a cherry-pick
git cherry-pick --abort
Cancels the cherry-pick and restores the branch to its pre-cherry-pick state. Use this if the conflicts are too complex or if you realize you picked the wrong commit. Nothing is permanently changed.
Skip a conflicting commit in a range
git cherry-pick --skip
When cherry-picking a range, --skip discards the current conflicting commit and moves on to the next one. Use this when a specific commit in the range is not relevant to the target branch and can be safely omitted.

How to Use

  1. Find the commit SHA you want to copy with git log --oneline branch-name.
  2. Switch to the target branch: git checkout target-branch.
  3. Run git cherry-pick SHA to apply the commit.
  4. Resolve any conflicts, then git add and git cherry-pick --continue.

Frequently Asked Questions

When should I use cherry-pick instead of merge?

Use cherry-pick when you only need specific commits from another branch, not the entire branch history. Common use cases: backporting a bug fix to an older release branch, moving a single feature commit to a different branch, or recovering a specific commit that was accidentally left off a release.

Does cherry-pick modify the original commit?

No — cherry-pick creates a new commit on the current branch with the same changes as the original. The original commit on its branch is unchanged. The new commit gets a different SHA because it has a different parent commit and potentially a different timestamp.

What is the difference between cherry-pick and rebase?

Cherry-pick applies specific individual commits you choose. Rebase replays a whole series of commits onto a new base. Use cherry-pick for surgical, targeted commit copying. Use rebase when you want to update an entire feature branch to include recent changes from main.

Related Tools