back to blog

WTF is `git cherry-pick`?

Written by Namit Jain·July 1, 2025·2 min read

You’ve got a hotfix chilling on dev that must land on main pronto. But merging dev would drag in half-baked features and who knows what else. Enter git cherry-pick your surgical code transplant tool.


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.


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.

Anatomy of the output

[main 5f8d3e2] Fix typo in README
 Author: teammate <teammate@example.com>
 Date:   Fri Jul 4 17:22:46 2025 +0530
  • 5f8d3e2: new commit hash no shady reuse.
  • Message & author carried over to keep context.

Conflict mode: activate

Conflicts are inevitable. When they hit:

  1. Fix markers (<<<<, ====, >>>>) in your favorite editor.
  2. git add <resolved-files>
  3. git cherry-pick --continue

Spooked? Reset with:

git cherry-pick --abort

Back to pre-cherry-pick bliss.


Pro tips

  • Cherry-pick small, self-contained commits large ones invite chaos.
  • Avoid cherry-picking merge commits unless you enjoy pain.
  • Push immediately after your successful pick don’t ghost your teammates.
  • Always ask: “Merge or cherry-pick?” If you need more than one commit, merging might be smarter.

Quick scenario

  1. Team fixes a critical bug on dev.

  2. Stakeholders demand it on main right now.

  3. Other dev commits? Unstable, unreviewed—thanks but no thanks.

  4. You:

    git checkout main
    git cherry-pick abc1234
  5. Customers: happy.

  6. You: legend.


Interactive demo

ecommerce-app

Current branch:main

Repository Branches

main
def4562024-01-10
Add user authentication system
alice2 file(s)
abc1232024-01-01
Initial commit
system1 file(s)
develop
jkl0122024-01-16
Add experimental payment feature
charlie2 file(s)
ghi7892024-01-15
Fix authentication bypass vulnerability
bob1 file(s)
def4562024-01-10
Add user authentication system
alice2 file(s)
abc1232024-01-01
Initial commit
system1 file(s)
hotfix
mno3452024-01-17
Critical security patch for auth
security-team1 file(s)
def4562024-01-10
Add user authentication system
alice2 file(s)
abc1232024-01-01
Initial commit
system1 file(s)
Terminal
Initialized git repository for ecommerce-app
Currently on branch: main
$

TL;DR

  • What: replay one commit onto another branch.
  • How: git cherry-pick <hash>.
  • Why: hotfixes, targeted changes, branch surgery.