Sometimes you need just one commit from another branch — not a full merge. That's what git cherry-pick is for.
What is cherry-pick?
It copies a single commit and applies it on top of your current branch. The original branch stays untouched.
How to do it
1. Find the commit hash
# Switch to the branch that has the commit you want
git log --oneline -10
# Example output:
# 8f4610d Add user profile page
# a3b2c1d Fix login bug
# ...
Copy the hash of the commit you need (e.g. 8f4610d).
2. Switch to your branch
# Go back to the branch where you want the commit
git checkout my-feature-branch
3. Cherry-pick the commit
# Apply the commit onto your current branch
git cherry-pick 8f4610d
That's it. The commit is now on your branch with a new hash.
4. Verify it worked
git log --oneline -3
# You should see the cherry-picked commit at the top
Handling conflicts
If the commit touches code that your branch has also changed, you'll get conflicts.
# Check which files have conflicts
git status
# Open and fix the conflicting files, then:
git add <fixed-files>
git cherry-pick --continue
To cancel and undo:
git cherry-pick --abort
Cherry-pick multiple commits
# Pick a range of commits (oldest..newest)
git cherry-pick abc1234..def5678
# Pick specific commits one by one
git cherry-pick abc1234 def5678 ghi9012
When to use it
- You need a bug fix from another branch but don't want to merge everything
- A teammate made a commit you depend on, and their branch isn't ready to merge yet
- You accidentally committed to the wrong branch and want to move it
When NOT to use it
- You need all changes from another branch — use
git mergeorgit rebaseinstead - The commit depends on previous commits in that branch — cherry-picking it alone might break things
Quick reference
| Command | What it does |
|---|---|
git cherry-pick <hash> |
Apply one commit |
git cherry-pick A B C |
Apply multiple commits |
git cherry-pick A..B |
Apply a range of commits |
git cherry-pick --abort |
Cancel and undo |
git cherry-pick --continue |
Continue after resolving conflicts |
Top comments (0)