Git Cherry Pick

Sometimes you do not want a full merge. You only need one commit from another branch, for example a bug fix. The git cherry-pick command copies a commit and applies it on your current branch as a new commit.

Syntax

git cherry-pick <commit>
git cherry-pick <commit1> <commit2>
git cherry-pick <start>..<end>
git cherry-pick -x <commit>
git cherry-pick --no-commit <commit>

Example

The branch develop has three commits. Only the footer fix is needed now on main, because we want to release it today.

Terminal output

$ git log –oneline develop
3baa9a1 (develop) Add search (not ready)
5cc9dfb Fix footer bug
88dbdb8 Add new menu (not ready)
1e3d759 (HEAD -> main) Add home

The “Fix footer bug” commit is the second from the top, which is develop~1.

Terminal output

$ git cherry-pick develop~1
[main 05dde3e] Fix footer bug
Date: Sat Jan 10 11:31:00 2026 +0000
1 file changed, 1 insertion(+)
create mode 100644 fix.txt
$ git log –oneline
05dde3e (HEAD -> main) Fix footer bug
1e3d759 Add home
$ ls
fix.txt
home.txt

Only the fix came to main. The other two commits are not in main. Notice that the commit has a different hash than the original, because it is a new commit.

Useful options

OptionMeaning
-xAdds “(cherry picked from commit …)” to the message, helpful in hotfix branches
-n or --no-commitApply the changes but do not commit, so you can change them
-eEdit the message of the new commit
--continue / --abortContinue or cancel after a conflict

Cherry-pick a range

git cherry-pick A..B
git cherry-pick A^..B

A..B does not include the commit A. A^..B includes both A and B.

If there is a conflict

Like a merge, Git stops when the same lines differ. Solve the conflict, run git add, and continue:

git cherry-pick --continue
git cherry-pick --abort

When to use it

  • Take a hotfix from develop to a release branch.
  • You committed to the wrong branch. Cherry-pick it to the right one, then remove it from the wrong one.
  • Take a single useful commit from a branch which will not be merged.
Note: Do not use cherry-pick too much. The same change then exists as two different commits, and a later merge can show confusing results. Normal merge is better when you need all the commits. Next: Git Reflog.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.