The git cherry-pick command: what it is and how to use it
In a hurry? Watch our brief 1-minute vertical video that summarizes the info below.
With the "cherry-pick" command, Git allows you to integrate selected, individual commits from any branch into your current HEAD branch.
Contrast this with the way commit integration normally works in Git: when performing a Merge or Rebase, all commits from one branch are integrated.

Cherry-pick, on the other hand, allows you to select individual commits for integration. In this example, only C2 is integrated into the master branch, but not C4.

How does cherry-pick actually work?
An important detail to understand: cherry-pick does not copy the full snapshot of a commit. Instead, it applies only the diff (the changes) that the commit introduced.
For example, say commit C on a feature branch adds file3.txt (while earlier commits A and B added file1.txt and file2.txt):
feature: A---B---C
|
C adds file3.txt
main: X---Y
|
(HEAD)
After running git cherry-pick C:
main: X---Y---C'
|
C' ONLY adds file3.txt (the diff of C)
NOT file1.txt or file2.txt
Notice that the new commit is called C' — cherry-pick always creates a completely new commit object with its own, new SHA identifier. Even though the changes are identical, the commit hash will be different from the original.
When should I use cherry-pick?
The short answer is: as rarely as possible. Because cherry-pick creates duplicate commits (new objects with new SHAs but the same changes), it should be reserved for situations where a traditional Merge or Rebase is not possible.
Here are the most common real-world scenarios where cherry-pick is the right tool:
1. Applying a hotfix to production
A critical bug is found and fixed on a feature branch. You need the fix on main immediately, but the feature branch isn't ready to be merged yet. Cherry-pick the fix commit directly onto main.
2. Saving commits from an abandoned branch
A pull request is closed or a feature branch is abandoned, but one or two commits contain valuable work. Cherry-pick those specific commits into another branch before deleting the old one.
3. Recovering lost commits
If you've accidentally deleted a branch, you can use git reflog to find the commit SHAs and cherry-pick them back:
$ git reflog
a1b2c3d HEAD@{0}: commit: Add login feature
f4e5d6c HEAD@{1}: commit: Fix timeout bug
$ git cherry-pick f4e5d6c
In all other cases, prefer Merge or Rebase to integrate changes.
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
How do I use the git cherry-pick command?
In its most basic form, you only need to provide the SHA identifier of the commit you want to integrate into your current HEAD branch:
$ git cherry-pick af02e0b
This way, the specified revision will directly be committed to your currently checked-out branch.
How to cherry-pick from another branch
The most common use case is cherry-picking a commit from one branch into another. Here's the step-by-step workflow:
Say you have a feature branch with several commits, and you want to bring just one of them (commit f) into main:
main feature
| |
| e---f---g
| /
a---b---c---d
|
(HEAD)
First, make sure you're on the branch that should receive the commit. Then, find the SHA of the commit you want and cherry-pick it:
$ git checkout main
$ git log feature --oneline # find the SHA of commit "f"
$ git cherry-pick <sha-of-f>
The result:
main feature
| |
| e---f---g
| /
a---b---c---d---f'
|
(HEAD)
Commit f' on main contains the same changes as f on the feature branch, but it's a new commit with its own SHA.
How to cherry-pick multiple commits
You can cherry-pick several commits at once by listing them:
$ git cherry-pick <sha-1> <sha-2> <sha-3>
The commits are applied in the order you list them (left to right), so always list them from oldest to newest to preserve the original sequence.
Cherry-picking a range of commits
If you need a consecutive series of commits, use the range syntax:
A---B---C---D feature
/
main
$ git cherry-pick A^..D
The A^..D notation means "from the parent of A through D" (inclusive). Without the ^, commit A itself would be excluded.
The result:
A---B---C---D feature
/
main---A'--B'--C'--D'
Cherry-picking without committing directly
If you would like to make some further modifications, you can also instruct Git to only add the commit's changes to your Working Copy — without directly committing them.
This is where the -n or --no-commit option comes in handy:
$ git cherry-pick -n af02e0b
After running this command, the changes from the commit af02e0b will be in your working directory and staging area, but no commit is created. You can then make additional changes and commit everything as a single, new commit.
This is useful when you want to:
- Combine changes from the cherry-picked commit with other modifications into one commit.
- Inspect or modify the cherry-picked changes before committing.
Cherry-picking merge commits
If you try to cherry-pick a merge commit, Git will stop with an error:
error: commit <sha> is a merge but no -m option was given
This happens because a merge commit has two parents, and Git doesn't know which side to diff against. The -m flag tells Git which parent to use:
A---B---M main (M is a merge commit with parents B and C)
\ /
C feature
$ git cherry-pick -m 1 <merge-sha> # diff against 1st parent (main-line)
$ git cherry-pick -m 2 <merge-sha> # diff against 2nd parent (feature)
In most cases, -m 1 is what you want — it replays the changes that the feature branch brought into the merge.
Resolving cherry-pick conflicts
When a cherry-pick causes a conflict, Git pauses and lets you resolve it manually:
$ git cherry-pick abc123
# CONFLICT (content): Merge conflict in file.txt
To resolve it:
# 1. Open the conflicting files and fix the conflicts
# 2. Stage the resolved files:
$ git add <resolved-files>
# 3. Continue the cherry-pick:
$ git cherry-pick --continue
If you decide you don't want to proceed with the cherry-pick at all, you can cancel it and return to the state before you started:
$ git cherry-pick --abort
Useful cherry-pick flags
Tracking the origin with -x
The -x flag appends a line to the commit message noting where the commit was originally cherry-picked from. This is especially useful when backporting between long-lived branches so collaborators can trace the origin:
$ git cherry-pick -x abc123
The resulting commit message will include:
Fix login timeout bug
(cherry picked from commit abc123...)
Editing the commit message with --edit
Use --edit (or -e) to open your editor and modify the commit message before the commit is created:
$ git cherry-pick --edit abc123
Adding a sign-off with --signoff
The --signoff (or -s) flag appends a "Signed-off-by" line with your name and email. This is required in many open-source projects (e.g., the Linux kernel):
$ git cherry-pick --signoff abc123
The resulting commit message will include:
Fix login timeout bug
Signed-off-by: Your Name <your@email.com>
Fast-forwarding with --ff
If the current HEAD is the direct parent of the commit you're cherry-picking, --ff will fast-forward your branch instead of creating a new commit:
$ git cherry-pick --ff abc123
Cherry-pick vs merge vs rebase
Cherry-pick is one of three ways to integrate commits in Git. Here's how they compare:
| Cherry-pick | Merge | Rebase | |
|---|---|---|---|
| What it does | Copies individual commits | Combines full branch history | Replays all commits onto a new base |
| Commit history | Creates duplicate commits (new SHAs) | Preserves all original commits | Rewrites history (new SHAs) |
| Use when... | Backporting a hotfix | Integrating a completed feature | Cleaning up history before merging |
| Avoid when... | You can merge or rebase instead | You want a linear history | The branch is shared with others |
Cherry-picking in Tower
If you're using the Tower Git client, you can cherry-pick one or multiple commits simply via drag and drop:
You can perform many complex Git operations with a simple drag and drop action in Tower. Click here to learn more about this feature.
Learn More
- Check out the chapter Merging Changes in our free online book
Get our popular Git Cheat Sheet for free!
You'll find the most important commands on the front and helpful best practice tips on the back. Over 100,000 developers have downloaded it to make Git a little bit easier.
About Us
As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.
Just like with Tower, our mission with this platform is to help people become better professionals.
That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.