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.
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:
git log --oneline feature656fd74 Add beta banner
ee659b1 Fix login crash
a5b9284 Add dark mode
10b77bf Release 1.0In 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:
git switch -q release
git cherry-pick feature~1
git log --oneline
cat login.txt[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
fixedThe 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:
lsapp.txt
login.txtOptions#
-x is useful on release branches, because it records where the fix came from. Try it with the last commit on feature:
git cherry-pick -x feature
git status --shortCONFLICT (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.txtConflicts#
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:
git cherry-pick --continue
git cherry-pick --abortWhen 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.
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
git cherry-pick dev > /dev/null
git log --oneline
ls3cc1e2e Add y
a1c1200 Start
a.txt
y.txtKey takeaway#
Next: git reset and the Reflog.
Finished this lesson?