Cherry-Picking Commits
Sometimes you need just one commit from another branch — an urgent fix, not the whole feature. git cherry-pick is the surgical tool for exactly that. By the end of this lesson you'll copy single commits, ranges of commits, and handle the conflicts that can arise.
Learn Cherry-Picking Commits in our free Git course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick reference.
Part of the free Git course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
1️⃣ Cherry-Picking a Single Commit
The core workflow: find the commit's hash on its source branch, switch to the branch that should receive it, then run git cherry-pick <hash> . Git applies that commit's changes as a new commit on your current branch — the original stays put on its own branch.
2️⃣ Multiple Commits & the -x Flag
You're not limited to one. List several hashes to pick them in order, or use a range A..B (which excludes A and includes everything after it up to B). Add -x to stamp each new commit with a "cherry picked from commit ..." line, so you can always trace a fix back to its source.
3️⃣ Handling Conflicts
Since cherry-pick replays a commit on a different base , its changes can clash with what's already there — a normal merge conflict. Resolve the markers, stage the file with git add , then run git cherry-pick --continue (not git commit ). To abandon the whole operation, use git cherry-pick --abort .
Your turn. Copy one bug-fix commit from feature onto main. Fill in the two blanks.
📋 Quick Reference
No commands given this time — just the plan. Move a single fix from a dev branch to main without the surrounding work.
Practice quiz
What does do?
- Deletes a commit
- Merges a whole branch
- Applies the changes from one specific commit onto your current branch
- Renames a commit
Answer: Applies the changes from one specific commit onto your current branch. Cherry-pick copies the changes of a single commit onto the branch you're on.
Before cherry-picking, which branch should you be on?
- The branch you want to RECEIVE the commit
- The branch the commit came from
- Always main
- It doesn't matter
Answer: The branch you want to RECEIVE the commit. Cherry-pick applies the commit to your current branch, so switch to the destination first.
Does the cherry-picked commit keep the original commit's hash?
- Yes, identical
- Only if it's annotated
- Only on main
- No — it becomes a new commit with a new hash
Answer: No — it becomes a new commit with a new hash. Cherry-pick creates a new commit (different parent), so it gets a new hash.
A good use of cherry-pick is...
- Copying an entire branch
- Pulling one urgent bug-fix commit into a release branch
- Deleting old commits
- Renaming branches
Answer: Pulling one urgent bug-fix commit into a release branch. Cherry-pick is ideal for grabbing a single needed commit without merging everything.
Can you cherry-pick more than one commit at once?
- Yes — list several hashes or a range
- No, only one ever
- Only two
- Only with merge
Answer: Yes — list several hashes or a range. You can pass multiple hashes, or a range like A..B, to cherry-pick several commits.
If a cherry-pick causes a conflict, after resolving you run...
- git commit --pick
- git merge --continue
- git cherry-pick --continue
- git rebase --continue
Answer: git cherry-pick --continue. Resolve, git add, then git cherry-pick --continue to finish.
How do you abandon an in-progress cherry-pick?
- git reset --hard
- git cherry-pick --abort
- Ctrl+C
- git cherry-pick --undo
Answer: git cherry-pick --abort. git cherry-pick --abort restores your branch to before the cherry-pick.
What does the flag add when cherry-picking?
- Nothing
- Extra conflict markers
- A new branch
- A line recording which original commit it came from
Answer: A line recording which original commit it came from. -x appends a '(cherry picked from commit ...)' note to the new commit's message.
How does cherry-pick differ from merge?
- They are the same
- Merge brings in a whole branch's history; cherry-pick takes individual commits
- Cherry-pick brings more commits
- Merge can't cause conflicts
Answer: Merge brings in a whole branch's history; cherry-pick takes individual commits. Merge integrates an entire branch; cherry-pick grabs only the specific commits you name.
After cherry-picking commit B onto main, where do the CHANGES from B live?
- Only on the source branch
- Deleted from both
- On main as a new commit (and still on the source branch)
- Only in the stash
Answer: On main as a new commit (and still on the source branch). The original stays put; a copy of its changes now also exists on main as a new commit.