Skip to content
Laviyx Learn

Try

Git and GitHub course menu

git cherry-pick: Copy a Commit to Another Branch

Copy a single commit from one branch to another with git cherry-pick, pick ranges of commits, handle conflicts, and know when to use it for hotfixes and release branches.

Advanced6 min readUpdated
On this page

git cherry-pick copies the change from one commit and applies it as a new commit on your current branch. Use it when you want one specific fix, not a whole branch.

A typical case: a bug fix was made on a feature branch, and the current release needs just that fix.

Pick one commit#

The feature branch has three commits, but release needs only the login fix:

Terminal
git log --oneline feature
Output
656fd74 Add beta banner
ee659b1 Fix login crash
a5b9284 Add dark mode
10b77bf Release 1.0

In real work you copy the commit's ID from the log. Here, feature~1 means the commit before the tip of feature, which is the fix:

Terminal
git switch -q release
git cherry-pick feature~1
git log --oneline
cat login.txt
Output
[release fd6c11b] Fix login crash
 Date: Thu Nov 5 09:10:00 2026 +0530
 1 file changed, 1 insertion(+), 1 deletion(-)
fd6c11b Fix login crash
10b77bf Release 1.0
fixed

The new commit has the same message and changes, but a different ID from the original, because its parent is different. The other commits on feature were not copied:

Terminal
ls
Output
app.txt
login.txt

Options#

CommandWhat it does
git cherry-pick ACopy one commit
git cherry-pick A BCopy two commits
git cherry-pick A^..CCopy the range from A to C, including A
git cherry-pick -x AAdd "(cherry picked from commit ...)" to the message
git cherry-pick -n AApply the changes, but do not commit

-x is useful on release branches, because it records where the fix came from. Try it with the last commit on feature:

Terminal
git cherry-pick -x feature
git status --short
Output
CONFLICT (modify/delete): theme.txt deleted in HEAD and modified in 656fd74 (Add beta banner).  Version 656fd74 (Add beta banner) of theme.txt left in tree.
error: could not apply 656fd74... Add beta banner
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
DU theme.txt

Conflicts#

That command stopped because Add beta banner changes theme.txt, a file that does not exist on release. That is a conflict, and git status --short shows it as DU.

Handle conflicts in the same way as in a merge: edit, then git add. Then finish, or cancel:

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

When not to use it#

Cherry-picking creates a copy of the change, so the same work exists twice with different IDs. If you later merge both branches, Git usually handles it, but the history is harder to read, and conflicts become more likely.

SituationBetter choice
You want all of a branchgit merge or git rebase
You committed on the wrong branchCherry-pick, then remove it with git reset
An urgent fix for a release branchCherry-pick is the right tool

Common mistakes#

Practice#

Practice exercise

From main, copy only the commit Add y from the dev branch (it is the tip of dev), then list the files.

Show solution
Terminal
git cherry-pick dev > /dev/null
git log --oneline
ls
Output
3cc1e2e Add y
a1c1200 Start
a.txt
y.txt

Key takeaway#

Next: git reset and the Reflog.

Finished this lesson?