Imagine you are working on an experimental feature branch with 30 commits that won't be ready for production for months. While coding, you discovered and fixed a critical security bug in commit 7d1935a. The production team needs that bugfix on main right now, but they cannot merge your unfinished feature branch. Git Cherry-Pick allows you to pluck that single commit out and apply it directly onto main.
# Step 1: Switch to the destination branch (where you want the commit to land):
$ git switch main
# Step 2: Cherry-pick the target commit hash:
$ git cherry-pick 7d1935a
[main 4f8e2a1] fix(security): sanitize user input against SQL injection
Date: Sun Nov 8 07:00:00 2026 +0000
1 file changed, 8 insertions(+), 2 deletions(-)
Notice that Git created a brand-new commit on main with a new hash (4f8e2a1), but preserved the exact diff, author information, and commit message from 7d1935a!
# Cherry-pick three distinct commits:
$ git cherry-pick 4a1b2c 8d9e0f 3f2a1b
# Cherry-pick a contiguous range of commits (from A to B, exclusive of A):
$ git cherry-pick A..B
# Cherry-pick a contiguous range INCLUSIVE of A:
$ git cherry-pick A^..B
-n / --no-commit)If you want to apply the changes to your working directory and staging area without automatically generating a commit:
$ git cherry-pick -n 7d1935a
If the cherry-picked commit touches code that differs on the destination branch, Git pauses and triggers a conflict:
git add [file].git cherry-pick --continue (do NOT run git commit!).git cherry-pick --abort.Strengthen your version control mastery by studying these connected classes:
Compare single commit cherry-picks with full multi-commit branch rebasing.
Understand how cherry-picking creates a new commit with identical diffs.
Resolve merge conflicts and advance cherry-picks with git cherry-pick --continue.
Cherry-pick a critical bugfix from develop into an urgent production release.
Advance your software engineering skills with the next topic in our synchronized curriculum.
Continue to git reflog Recovery → Previous: ← Refs, HEAD & Symrefs | Full Syllabus