Ever wished you could steal just one commit without dragging the entire messy branch with it?
Welcome to Git’s commit heist tool: git cherry-pick
.
What actually happens?
Run:
git checkout main
git cherry-pick <commit-hash>
`
Git grabs the diff from <commit-hash>
and replays it on main
as a brand-new commit.
Same content, fresh identity (new hash).
Why you need this
✅ Hotfix emergencies: pluck that one bugfix without the noise.
✅ Selective feature moves: steal just the feature you want.
✅ History hacks: clean up messy branches by cherry-picking verified commits.
💡 Pro tip: If you need more than 3 commits, merging might be smarter. Don’t over-cherry-pick like a code raccoon.
Anatomy of the output
bash
[main 5f8d3e2] Fix typo in README
Author: teammate <teammate@example.com>
Date: Fri Jul 4 17:22:46 2025 +0530
-
5f8d3e2
→ brand new hash, no shady reuse. - Message & author? Still carried over for context clarity.
Conflict mode: activate
Conflicts are inevitable. When they hit:
- Fix markers (
<<<<
,====
,>>>>
) in your favorite editor. git add <resolved-files>
- Continue the drama:
bash
git cherry-pick --continue
⚠️ WTF moment: Cherry-pick conflicts are like that one friend who says “I’ll be chill” and then flips the table.
Spooked? Reset with:
bash
git cherry-pick --abort
Back to pre-cherry-pick bliss.
Pro tips
✅ Cherry-pick small, self-contained commits. Big ones? Big drama.
✅ Avoid merge commits unless you enjoy pain.
✅ Push right after you pick. Don’t ghost your teammates.
Quick scenario
- Team fixes a critical bug on
dev
. - Stakeholders demand it on
main
right now. - Other commits? Unstable, unreviewed. Nope.
- You pull the heist:
bash
git checkout main
git cherry-pick abc1234
- Customers: happy.
- You: legend.
Interactive demo
Visit https://www.namitjain.com/blog for interactive demo
TL;DR
- What: Steal a commit like Ocean’s Eleven.
- How:
bash
git cherry-pick <hash>
- Why: Hotfixes, targeted changes, branch surgery.
🔥 Next WTF:
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.