Back
GitoryxGitoryx
Intermediate9 min read

Git Cherry Pick Tutorial: Apply Specific Commits

Cherry-picking lets you apply any commit from any branch to your current branch — without merging everything. This tutorial shows you exactly how to use it, and when not to.

The Problem

A critical bug fix is sitting on a feature branch, but you need it on main right now — without merging the entire feature. Or a colleague committed something useful on their branch and you need just that one change. You don't want to merge everything, and rebase would be overkill.

Cherry-pick lets you apply any specific commit to any branch, surgically. It's the right tool when you need to port a fix, backport to a release branch, or rescue a single commit without bringing in unrelated changes.

Common mistakes developers make with this:

  • Cherry-picking instead of merging when you actually need all the commits
  • Creating duplicate commits across branches and getting confused during later merges
  • Cherry-picking a commit that depends on earlier commits (causing broken state)
  • Not checking for conflicts before cherry-picking across diverged branches

Gitoryx: In Gitoryx, you can drag any commit from the visual graph onto another branch to cherry-pick it. The graph shows you the result immediately — including any conflicts before you commit.

What is Cherry Pick Tutorial: Apply Specific Commits?

Git cherry-pick applies the changes from one or more specific commits to your current branch. Unlike merge or rebase, it doesn't bring in the entire branch history — just the diff of the selected commits, replayed on top of your current HEAD.

Step-by-Step Guide

1

Find the commit SHA you want to cherry-pick

You need the SHA of the commit you want to apply. Use `git log` to browse commits on any branch, or use `git log --oneline` for a compact view.

bash
# View commits on another branch
git log --oneline feature/payment-fix

# View all branches in a graph
git log --oneline --graph --all

# Example output:
# a3f2c1d Fix null pointer in payment processor   ← this is what we want
# b9e1a2f Add PaymentForm component
# c4d5e6f Initial payment module

You only need the first 7 characters of the SHA in most cases. Git accepts short SHAs as long as they're unambiguous.

2

Cherry-pick a single commit

Switch to the target branch, then run `git cherry-pick <sha>`. Git applies the commit's diff and creates a new commit with a new SHA but the same changes and message.

bash
# Switch to the branch where you want the commit
git checkout main

# Apply the specific commit
git cherry-pick a3f2c1d

# Result:
# [main 7b8c9d0] Fix null pointer in payment processor
# 1 file changed, 3 insertions(+), 1 deletion(-)

The cherry-picked commit gets a new SHA because its parent commit is different. The content is identical, but it's technically a new commit.

3

Cherry-pick multiple commits

You can cherry-pick several commits at once. List them individually, or use a range. Order matters — commits are applied from left to right.

bash
# Cherry-pick two specific commits
git cherry-pick a3f2c1d e7b1f9a

# Cherry-pick a range (inclusive of both ends)
git cherry-pick a3f2c1d^..e7b1f9a

# Cherry-pick all commits from a branch tip (last 3 commits)
git cherry-pick HEAD~3..HEAD

When cherry-picking a range, make sure the commits are in dependency order. If commit B depends on commit A, cherry-picking B alone will likely cause conflicts or a broken state.

4

Handle conflicts during cherry-pick

If the cherry-picked changes conflict with your current branch, Git pauses and asks you to resolve them — exactly like a merge conflict.

bash
# Git pauses with:
# CONFLICT (content): Merge conflict in src/payment.ts
# error: could not apply a3f2c1d... Fix null pointer in payment processor

# 1. Resolve the conflict in your editor
# 2. Stage the resolved file
git add src/payment.ts

# 3. Continue the cherry-pick
git cherry-pick --continue

# Or abort entirely to go back to where you started
git cherry-pick --abort
See this workflow in Gitoryx — Gitoryx demo

See this workflow in Gitoryx. Drag any commit from the visual graph onto any branch to cherry-pick it — no SHA lookup needed.

Free download
5

Cherry-pick without committing immediately

Use `--no-commit` to apply the changes to your working directory and staging area without creating a commit. Useful when you want to cherry-pick multiple commits and squash them into one.

bash
# Apply the changes but don't commit yet
git cherry-pick --no-commit a3f2c1d
git cherry-pick --no-commit e7b1f9a

# Review the combined changes
git diff --staged

# Commit everything as one
git commit -m "Port payment fix and error handling from feature branch"

Combining `--no-commit` across multiple cherry-picks is a clean way to backport a logical group of changes as a single commit on the target branch.

6

Backport a fix to a release branch

A common real-world use case: a bug is fixed on main but needs to go into the `v2.1` release branch too. Cherry-pick is the right tool here.

bash
# Bug was fixed on main with commit d9a8b7c
git checkout release/v2.1

# Port the fix to the release branch
git cherry-pick d9a8b7c

# Push the release branch
git push origin release/v2.1

Common Mistakes to Avoid

Cherry-picking when you should merge

If you need all or most commits from a branch, cherry-picking each one is tedious and creates duplicate commits. When the feature branch eventually merges into main, Git sees those commits as different (different SHAs) and can produce confusing merge conflicts.

Fix: Use cherry-pick for surgical, one-off commit porting. For integrating an entire branch, use merge or rebase instead.

Cherry-picking a commit without its dependencies

If commit B introduces a function that commit A defined, cherry-picking B without A leaves your code in a broken state. The cherry-pick may succeed without conflicts but still produce broken code.

Fix: Always check what a commit depends on (`git show <sha>` and review the context). Cherry-pick all necessary dependency commits together.

Losing track of which commits were cherry-picked where

Over time, the same logical change exists as multiple commits with different SHAs across branches. This makes it hard to know what has been ported where, especially during audits or when resolving merge conflicts.

Fix: Document backports in the commit message (e.g., 'cherry-picked from main: d9a8b7c') or use tools that track this. Some teams use `git cherry` to identify un-ported commits.

Gitoryx — visual Git client for macOS, Windows & Linux
GitoryxGitoryx — macOS, Windows & Linux

Cherry-Pick Commits Visually in Gitoryx

  • Drag any commit from the visual graph onto any branch to cherry-pick it — no SHA lookup needed.
  • Gitoryx highlights which commits on other branches have not yet been ported to your current branch.
  • The graph shows the new cherry-picked commit immediately after the operation.
  • Conflict resolution is integrated — Gitoryx opens the diff view if a conflict occurs during cherry-pick.
  • Cherry-pick ranges by selecting multiple commits in the graph with Shift+click.
Download Gitoryx — FreemacOS · Windows · Linux · No subscription

Frequently Asked Questions

What does git cherry-pick do?

Git cherry-pick applies the changes introduced by a specific commit onto your current branch. It takes the diff from that commit and replays it on top of your current HEAD, creating a new commit with the same changes but a different SHA.

Is git cherry-pick safe to use on shared branches?

Yes — cherry-pick only adds new commits, it never rewrites existing history. It's safe to cherry-pick onto shared branches and push normally without force-pushing.

What is the difference between cherry-pick and merge?

Merge integrates the full history of another branch into yours. Cherry-pick applies only the changes from one specific commit, without bringing in any other commits from that branch. Use merge when you want everything; use cherry-pick when you want just one thing.

What is the difference between cherry-pick and rebase?

Rebase replays all commits from your branch onto a new base, in order. Cherry-pick applies a specific chosen commit from anywhere to your current branch. Rebase is for updating a branch; cherry-pick is for porting individual changes.

Can git cherry-pick cause conflicts?

Yes. If the code around the cherry-picked change has diverged significantly between branches, Git will pause with a conflict. Resolve it just like a merge conflict: edit the file, `git add`, then `git cherry-pick --continue`.

How do I cherry-pick a range of commits?

Use `git cherry-pick A^..B` to apply all commits from A to B inclusive (the `^` excludes A from the range notation, so you need it to include A). Or list them individually: `git cherry-pick sha1 sha2 sha3`.

Does cherry-pick duplicate a commit?

It duplicates the changes, not the commit itself. A cherry-picked commit gets a new SHA because its parent is different. Both branches will have commits with the same diff but different identities in Git's history.

When should I NOT use cherry-pick?

Avoid cherry-pick when you need all commits from a branch (use merge), when commits have complex dependencies that make individual porting risky, or when it would create many duplicate commits that will confuse future merges.

See it in action with Gitoryx

Everything in this tutorial is faster and clearer with a visual Git client. Gitoryx is free, runs natively on macOS, Windows, and Linux, and built for developers who want to move fast without breaking things.