git cherry-pick
intermediateRe-apply one specific commit onto your current branch.
git cherry-pickWhat it does
git cherry-pick takes the changes introduced by any commit and replays them as a NEW commit on your current branch. It's your survival tool for 'get that one fix over here' across branches — without merging or rebasing whole histories.
The fix commit is duplicated onto release with the identical diff but a new hash
Watch it — press play
A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.
Step 1
One fix, other branch too
A hotfix landed on main, but the release branch needs it right now — without merging all of main.
git cherry-pick c1d8e2fThe fix commit — about to travel
Under the hood
A narrowed three-way merge
Cherry-pick diffs the picked commit against its own parent, then three-way-merges that diff onto your current HEAD. The result is a new commit with fresh hash and a fresh parent — but identical content change.
main — A — B picked commit: X (on feature) result: A — B — X' X' has same diff, new identity
Cherry-picking a range
`git cherry-pick A..B` replays every commit in that range, in order — a poor-man's selective rebase. Useful when a branch has exactly the fixes you want and nothing else.
Conflicts behave like merge conflicts
If 'your' current branch already changed the same lines, cherry-pick stops and asks you to resolve — markers in the file, then git cherry-pick --continue (or --abort).
Aliases the pros type
Memorize the git cherry-pick concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:
git config --global alias.st # → git cherry-pickg cpgit cherry-pickThe classic rescue alias.
g cp -xgit cherry-pick -xKeep provenance — traces back to the original fix.
Command anatomy
-nApply the changes but don't commit — merge a few picks first.
--continue / --abortFinish or bail out of a conflicted pick.
-xAdd '(cherry picked from commit …)' to the message as provenance.
When to reach for it
A hotfix commit landed on main but the release branch needs it right now.
You committed to the wrong branch: cherry-pick it out, then reset the wrong branch.
Selectively assembling a release from several feature branches.
Pro tip
Committed to the wrong branch? `git cherry-pick <hash>` onto the right branch, then `git reset --hard HEAD~1` on the wrong one. That two-step is one of the most common recovery dances in a working day.