DEV Community

Namit Jain
Namit Jain

Posted on

WTF is git cherry-pick?

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>
Enter fullscreen mode Exit fullscreen mode


`

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:

  1. Fix markers (<<<<, ====, >>>>) in your favorite editor.
  2. git add <resolved-files>
  3. 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

  1. Team fixes a critical bug on dev.
  2. Stakeholders demand it on main right now.
  3. Other commits? Unstable, unreviewed. Nope.
  4. You pull the heist:

bash
git checkout main
git cherry-pick abc1234

  1. Customers: happy.
  2. 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:

“WTF is git rebase (and Why It’s Both Magic and Chaos)”

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.