What Does git cherry-pick Do?

What Does git cherry-pick Do?

A deep, no-assumptions walkthrough of Git's most surgical command — how it copies a single commit from one branch to another, why conflicts happen, and when to actually reach for it.

Imagine a chef who has spent all afternoon preparing an enormous ten-course tasting menu, and a food critic walks by and says, “I don’t want the whole menu — I just want that one incredible dessert from course seven, and I want it served on my own table right now.” The chef can’t hand over the entire ten-course experience; they need to carefully lift just that one dish, recreate it exactly, and place it in front of the critic, without disturbing anything else on either table. git cherry-pick is Git’s version of that request: instead of merging an entire branch’s worth of history, it lets you reach into someone else’s line of work, grab exactly one commit, and recreate it — cleanly and deliberately — on your own branch.

1What Is git cherry-pick?

Let’s build a precise, plain-English definition before touching any internals.

The Simple Definition

git cherry-pick is a command that takes the changes introduced by one specific commit — anywhere in your project’s history, on any branch — and applies those same changes as a brand-new commit on the branch you’re currently on. The original commit stays exactly where it was; cherry-picking creates a fresh copy of its changes elsewhere, with a new commit identity of its own.

Simple Analogy

Think of a photocopier that can duplicate a single page from one binder and staple that copy into a completely different binder. The original page in the first binder is untouched — you now simply have two separate copies of the same content, living in two different places, each with its own life going forward.

Why This Command Exists

Most of the time, when you want changes from one branch on another, a merge or a rebase is exactly the right tool — they bring over everything a branch has to offer. But sometimes you genuinely want just one specific change, and nothing else that branch contains. Maybe a critical bug fix was made on a long-running experimental branch that isn’t ready to be merged in its entirety. Maybe you need to apply the exact same small fix to three different release versions of your software. git cherry-pick exists precisely for these narrow, surgical situations, where a full merge would be the wrong tool for the job.

i
Key Idea

Cherry-picking copies the effect of a commit, not the commit itself. The result is a brand-new commit, with its own unique identity, even though the actual code changes it introduces are identical to the original.

2A Quick Refresher: What a Commit Actually Is

Cherry-picking only makes sense once you understand exactly what’s being copied, so let’s ground ourselves here first.

A commit is a saved snapshot of your entire project at one specific point in time, along with a description of what changed and who made the change. But Git doesn’t store a commit as a standalone island — every commit (except the very first one in a project) also remembers which commit came directly before it, called its “parent.” This chain of parent links is what forms the branching, weaving structure of a project’s history that tools like Git log visualize as a graph.

The Snapshot

Tree

A complete record of every file and folder’s exact content at the moment of the commit — not just what changed, but the full state of everything.

The Story

Diff

The difference between a commit’s tree and its parent’s tree — in other words, exactly what was added, removed, or modified by this one commit specifically.

The Link

Parent

A reference to the commit that came immediately before this one, forming the chain that gives Git its entire sense of history and order.

The Label

Message and Metadata

The human-readable description of the change, along with the author’s name, email, and timestamp, all permanently attached to the commit.

i
Key Idea

When Git cherry-picks a commit, it’s really working with that commit’s diff — the specific change it introduced relative to its own parent — and figuring out how to apply that same change onto a completely different starting point.

3How git cherry-pick Works Internally

Now let’s open the hood and walk through exactly what Git does, step by step, when you cherry-pick a commit.

1

Git identifies the target commit’s diff

Git computes exactly what changed between the commit you’re cherry-picking and its own parent — the same diff calculation described in Chapter 2.

2

Git attempts to apply that diff to your current branch

Using your current branch’s latest commit as the new starting point, Git tries to apply the exact same set of changes on top of it, as if you had made those edits yourself right now.

3

If it applies cleanly, a new commit is created

Assuming the surrounding code hasn’t diverged too much, the change applies without any issue, and Git creates a brand-new commit on your current branch containing that exact change.

4

The new commit gets a fresh identity

Even though the content of the change is identical, this new commit is entirely distinct from the original — it has its own unique commit identity, its own parent (your branch’s previous tip), and typically the current date as its commit timestamp.

5

The original commit’s authorship is preserved

By default, Git keeps the original commit’s author information intact on the new commit, giving proper credit to whoever actually wrote the change, even though you’re the one who copied it over.

graph LR
    subgraph "Source Branch"
    P1[Parent Commit] --> C1[Commit X - the fix]
    end
    subgraph "Your Branch"
    P2[Your Latest Commit] -- cherry-pick Commit X --> C2[New Commit X' - same change, new identity]
    end
        
FIG 1 — Cherry-picking recreates a commit’s changes as a brand-new commit elsewhere, leaving the original untouched.

4The Full Lifecycle of a Cherry-Pick

Zooming out from the internal mechanics, here’s what the whole process looks like from a developer’s point of view, start to finish.

sequenceDiagram
    participant You as Your Branch
    participant Src as Source Commit (elsewhere)
    You->>Src: Identify the exact commit to copy
    You->>You: Switch to the branch that should receive it
    You->>You: Run cherry-pick, pointing at that commit
    You->>You: Git computes and attempts to apply the diff
    alt Applies cleanly
        You->>You: New commit created automatically
    else Conflict detected
        You->>You: Git pauses, marks conflicting lines
        You->>You: You manually resolve, then continue
    end
    You->>You: Cherry-pick complete — new commit now on your branch
        
FIG 2 — Whether or not a conflict occurs, cherry-picking always ends the same way: one new commit on your current branch.

Notice that this lifecycle mirrors, in miniature, the same automatic-versus-manual logic you’d find in a full merge — Git tries its best to combine things automatically, and only asks for human judgment when it genuinely can’t decide safely on its own. Cherry-picking is, in a sense, a merge scaled down to the size of exactly one commit.

5Picking a Single Commit vs. a Range

Cherry-picking isn’t limited to exactly one commit at a time — it can also be used to copy over a whole consecutive sequence.

Single-Commit Cherry-Pick

The most common and straightforward case: you identify one specific commit, and Git recreates just that one change on your branch. This is the scenario most people picture when they think of cherry-picking.

Range Cherry-Pick

Git also supports specifying a consecutive range of commits, applying each one, in order, as its own separate new commit on your branch. This is useful when several related commits together form one coherent piece of work you want to copy as a group, rather than cherry-picking each one individually by hand.

!
Common Misconception

Cherry-picking a range does not create one combined commit — it faithfully recreates each original commit in the range as its own separate new commit, preserving the same step-by-step history, just relocated.

Multi-Commit Feature on a Discarded Branch

If a small feature was built across three tidy, well-organized commits on a branch that ultimately won’t be merged as a whole, cherry-picking that range lets you salvage exactly those three commits onto a branch that will actually ship.

6Cherry-Pick Conflicts — Why They Happen

This is the part beginners find most intimidating, so let’s demystify it fully, the same way we would for a merge.

A conflict happens when the surrounding code on your current branch has diverged enough from the commit’s original context that Git can’t confidently figure out where the change belongs anymore. Remember, Git is applying a diff — a description of “change line 12 from this to that” — and if line 12 on your branch no longer matches what the diff expects to find there, Git has no safe way to guess what you’d want instead.

Simple Analogy

Imagine trying to paste a printed photo into a scrapbook page that’s been redesigned since the photo was originally cut out — if the shape and layout of the page has changed too much, the photo simply doesn’t fit where it used to, and someone needs to manually figure out how to make it work on the new page.

!
Common Misconception

A cherry-pick conflict does not mean the change was wrong, or that something is broken. It simply means the target branch’s surrounding code has moved on since the original commit was written, and Git needs your judgment to reconcile the two.

7Resolving a Cherry-Pick Conflict, Step by Step

Once you understand why a conflict happens, resolving one is a calm, mechanical process, very similar to resolving a merge conflict.

1

Git pauses mid-operation

Instead of completing the cherry-pick automatically, Git stops and clearly marks exactly which file or files contain the conflicting section.

2

Open the file and review the markers

Inside the affected file, Git inserts clear markers showing both what your branch currently has and what the incoming commit was trying to introduce, side by side.

3

Decide on the correct final content

You edit the file by hand, choosing to keep your version, the incoming change, a thoughtful blend of both, or something new entirely, based on what actually makes sense in the current context.

4

Mark the file as resolved

Once you’re satisfied with the final content, you tell Git the conflict in this file has been settled.

5

Continue the cherry-pick

With every conflicted file resolved, you tell Git to continue, and it finalizes the new commit on your branch exactly as it would have if no conflict had occurred at all.

i
Key Idea

Just like an in-progress merge, an in-progress cherry-pick can always be safely abandoned before it’s finalized, returning your branch to exactly how it looked beforehand — nothing is permanently changed until you deliberately complete the resolution.

8Cherry-Pick vs. Merge vs. Rebase

These three commands all combine changes from one place into another, but at very different scopes and with very different intentions.

CommandScopeTypical Intent
Cherry-PickOne specific commit (or a short range)“I want exactly this one change, and nothing else.”
MergeAn entire branch’s history“I want everything this branch has to offer, combined into mine.”
RebaseAn entire branch’s history“I want to replay my whole branch on top of a new starting point.”
Simple Analogy

If a branch’s history is a shelf of many books, merging brings the entire shelf over and stitches it in alongside yours, rebasing repositions your entire shelf to start from a new point, and cherry-picking simply photocopies one specific page out of one specific book on that shelf.

i
Key Idea

Under the hood, cherry-picking and rebasing actually share the same core mechanism — both work by taking a commit’s diff and reapplying it on top of a new starting point. Rebasing is really just cherry-picking an entire sequence of commits, one after another, automatically.

9Common Options You’ll See Used with git cherry-pick

A few options change the default behavior of cherry-pick in ways you’ll run into regularly. Here they are, described conceptually.

Don’t Finish Yet

No-Commit Mode

Applies the change to your working files without immediately finalizing a new commit, letting you review, tweak, or combine it with other edits before committing.

Give Credit

Sign-Off

Adds a line to the new commit’s message noting who applied the cherry-pick, useful for projects that require a formal trail of who touched what.

Change Nothing Yet

Continue / Abort / Skip

After a conflict, these let you finish resolving and proceed, cancel the whole operation and return to where you started, or skip just the problematic commit when cherry-picking a range.

Multiple Parents

Mainline Selection

Needed specifically when cherry-picking a merge commit, since a merge commit has more than one parent and Git needs to know which parent’s perspective to use for computing the diff.

10Advantages and Trade-offs

Like every precise tool, cherry-picking brings genuine benefits alongside some sharp edges worth understanding.

Advantages

  • Lets you copy exactly one useful change without pulling in an entire branch’s unrelated history.
  • Extremely useful for applying critical fixes across multiple release versions at once.
  • Preserves the original author’s credit on the newly created commit.
  • Works cleanly and automatically the vast majority of the time, when surrounding code hasn’t diverged much.
  • Gives fine-grained, deliberate control over exactly what enters your branch’s history.

Disadvantages / Trade-offs

  • Creates a duplicate commit with a different identity, which can make history harder to trace if overused.
  • Doesn’t automatically track that a change came from another branch, so context can get lost over time.
  • Repeated, heavy cherry-picking across many branches can lead to subtle, hard-to-track divergence.
  • Conflicts, while manageable, still require the same careful manual attention as a merge conflict.

11Security Considerations

Cherry-picking touches a few security-relevant scenarios worth being aware of.

Backporting Security Fixes

One of cherry-pick’s most important real-world uses is applying a critical security patch, originally made on the latest development branch, backward onto older, still-supported release branches — without dragging along unrelated, unvetted changes.

Accidentally Reintroducing Removed Code

Cherry-picking an old commit can sometimes unintentionally bring back code, or even sensitive data, that was deliberately removed later in the source branch’s own history — worth double-checking before applying an old commit.

Preserving an Audit Trail

Because cherry-picking preserves the original author’s identity, it helps maintain an honest audit trail of who actually wrote a given change, even as that change travels across multiple branches.

12Design Patterns and Anti-Patterns

Over years of real-world use, a few clear patterns of good and bad cherry-pick usage have emerged across teams.

Pattern: Hotfix Backporting

A well-established, healthy pattern where a critical fix is made once on the main development line, then deliberately cherry-picked onto each actively supported release branch that needs it.

Pattern: Rescuing Work from an Abandoned Branch

When an experimental branch is ultimately discarded, cherry-picking the handful of genuinely valuable commits out of it before deleting the rest is a clean, deliberate way to salvage good work.

ANTI-PATTERN-01 Avoid
Problem

A team uses cherry-picking as their primary, everyday way of moving work between branches, instead of properly merging or rebasing feature branches when the situation calls for it.

Why It’s Harmful

Repeated, routine cherry-picking creates dozens of duplicate commits scattered across branches, none of which Git recognizes as related to one another, making it extremely difficult to later merge those branches cleanly or understand the project’s true history.

Correct Approach

Reserve cherry-picking for genuinely narrow, deliberate situations — like backporting a specific fix — and use proper merges or rebases for moving an entire branch’s work between lines of development.

ANTI-PATTERN-02 Avoid
Problem

A developer cherry-picks a commit without checking what else that commit depended on earlier in its original branch’s history.

Why It’s Harmful

If the cherry-picked commit relies on a function, variable, or file introduced by an earlier commit that wasn’t also copied over, the change may fail to apply cleanly, or worse, apply but break at runtime in confusing ways.

Correct Approach

Before cherry-picking, briefly review the commit’s context and confirm whether it truly stands alone, or whether it needs to be cherry-picked together with the specific commits it depends on.

13Best Practices and Common Mistakes

A practical checklist for using cherry-pick the way it’s genuinely meant to be used.

Do

Confirm the commit is truly self-contained

Before cherry-picking, check that the commit doesn’t quietly depend on other changes from its original branch that you’re not also bringing over.

Do

Test after every cherry-pick

Since the surrounding context is different on your branch, always verify the change still behaves correctly in its new home, even if it applied without a conflict.

Avoid

Using it as a substitute for merging

Reaching for cherry-pick to move an entire feature’s worth of commits, one by one, is a sign that a proper merge or rebase is actually the right tool.

Avoid

Cherry-picking without reading the change

Blindly copying a commit without understanding what it actually does risks introducing unwanted or unreviewed behavior onto an important branch.

14Real-World and Industry Examples

Cherry-picking sits quietly behind several important, everyday practices across the software industry.

1 diff
is all a cherry-pick ever moves at its core
Multiple
release branches a single fix can be backported to
New ID
every cherry-picked commit receives, even with identical content

Long-Term Support Software Releases

Operating systems, browsers, and enterprise software with multiple simultaneously supported versions rely heavily on cherry-picking to apply the same critical fix across several release branches at once.

Open-Source Project Maintenance

Maintainers of popular libraries often cherry-pick a specific bug fix out of a large, not-yet-ready feature branch, so users don’t have to wait for the entire feature to be finished before benefiting from the fix.

Cross-Team Collaboration

In larger organizations, one team occasionally needs a specific improvement made by another team’s branch without wanting to inherit that whole branch’s unrelated, in-progress work — cherry-picking is the natural tool for exactly this.

15Frequently Asked Questions

Q1Does cherry-picking remove the commit from its original branch?

No. The original commit stays exactly where it was, completely untouched. Cherry-picking only creates a new, separate commit elsewhere with the same changes.

Q2Will Git remember that a cherry-picked commit came from another branch?

Not automatically in a structural sense, though many teams add a note in the new commit’s message referencing the original commit for future clarity.

Q3Can I cherry-pick a commit from a completely different, unrelated repository?

Not directly — cherry-pick works within the history of a single repository. To bring in a commit from an entirely separate repository, you’d first need to connect the two histories in some way.

Q4What happens if I cherry-pick the same commit twice?

Git will attempt to apply the same change again. If nothing on your branch has changed since the first cherry-pick, this second attempt will usually have nothing meaningful left to apply, or may create an empty commit.

Q5Is cherry-picking considered rewriting history?

No — unlike a rebase, cherry-picking never alters any existing commit. It only ever adds a new commit, making it just as safe to use on shared branches as a regular merge.

Q6Can I cherry-pick a merge commit?

Yes, though it requires telling Git which of the merge commit’s multiple parents should be treated as the baseline for computing the diff, since a merge commit doesn’t have just one.

16Summary and Key Takeaways

git cherry-pick is Git’s tool for surgically copying the effect of one specific commit onto your current branch, without bringing along the rest of that commit’s original branch. Under the hood, it computes the commit’s diff and attempts to reapply it on top of your branch’s latest commit, creating a brand-new commit with its own identity while preserving the original author’s credit. It’s an invaluable tool for backporting critical fixes and rescuing isolated good work from otherwise-discarded branches, but its power comes with a responsibility to use it deliberately, rather than as a routine substitute for merging or rebasing.

Key Takeaways

  • Copies the effect, not the commit — the original stays untouched; a brand-new commit is created elsewhere.
  • Built on a diff — cherry-pick works by computing a commit’s changes and reapplying them on a new starting point.
  • Conflicts are normal — they simply mean the surrounding code has diverged since the original commit was written.
  • Never rewrites history — unlike a rebase, cherry-picking only ever adds new commits, making it safe on shared branches.
  • Best for narrow, deliberate use — ideal for backporting fixes or rescuing isolated commits, not for moving whole features.
  • Check for hidden dependencies — a commit that relies on earlier, uncopied changes may fail or misbehave once cherry-picked.
  • Related to rebasing under the hood — a rebase is essentially cherry-picking an entire sequence of commits automatically.