Stop 05 · Git & GitHubTopics · 7/11

Cherry Pick

Part of the Frontend Developer Roadmap

In short

Sometimes you need just one commit from another branch, not the whole branch. Cherry-pick copies that single commit onto the branch you're on.

`git cherry-pick <commit>` applies a single specific commit from one branch onto another, without merging the whole branch. It is useful for selectively moving a fix or feature, but repeated cherry-picks can create duplicated history and should be used intentionally.

The jaadu mascot picks one golden mango out of a full crate at a fruit stall.

Think of it like this

Picking one mango from the crate

At the fruit stall you don't buy the whole crate when you want one perfect mango. Cherry-pick is the same. Out of a branch full of commits, you pick the one you need and carry only that home.

Watch it happen

Copying one fix to main

m1 Release
m2 Hotfix site
GST fix (copy)
4b7d8e0 UPI wip
9f3c2a1 GST fix

1/5feature/payments has two commits: a half-done UPI screen and a finished GST rounding fix.

The big ideas

What you need to know

Copies, doesn't move

The original commit stays on its branch. A copy with a new ID lands on your current branch.

Perfect for hotfixes

A bug fix was made on a feature branch but production needs it now. Cherry-pick just the fix onto main.

You need the hash

Find the commit ID with git log, then pass it to git cherry-pick.

Don't overuse it

Copying many commits around creates duplicates. If you need most of a branch, merge it instead.

See it in code

Walk through the code

bash
1# Find the commit you want2git log --oneline feature/payments3# 9f3c2a1 Fix GST rounding on invoice4# 4b7d8e0 Add UPI payment screen (not ready)5 6git switch main7git cherry-pick 9f3c2a18 9# Conflict? Fix it, then:10git add invoice.js11git cherry-pick --continue

1/3List the feature branch's commits and note the ID of the one you want.

Only the GST fix comes to main. The half-done UPI screen stays on the feature branch until it's ready.

Save yourself the pain

Common mistakes

Oops

Cherry-picking a commit that depends on earlier commits you didn't pick.

Do this instead

Check what the commit relies on. Pick those too, or merge the branch instead.

Oops

Using cherry-pick as your normal way to move work between branches.

Do this instead

Use merge or rebase for everyday work. Save cherry-pick for one-off fixes.

Your mission

Rescue one fix

~15 min

Quick check

After cherry-picking commit 9f3c2a1 onto main, what's true?

Go deeper

  1. 1Cherry-pick a single commit from one branch onto another in a sandbox repo. Validate your understanding by applying it in a small practical example.
  2. 2Learn when cherry-pick is the right tool — e.g. hotfixing a specific change to a release branch. Focus on understanding the underlying reason it works, not only memorizing the definition.
  3. 3Understand that cherry-picking creates a new commit with a different hash.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge