Apply one specific commit to another Git branch

Use cherry-pick to apply a selected change, inspect its dependencies, and handle conflicts or merge commits explicitly.

Best practices
Illustration of Git branches and version history

Use git cherry-pick COMMIT when you want a particular commit's change on your current branch. A merge integrates history reachable from another tip; it cannot generally select just one arbitrary change from that history.

Select the commit and destination

Start with a clean working tree, then inspect the change before applying it:

git switch main
git log --oneline feature-x
git show a1b2c3d
git cherry-pick a1b2c3d

Replace the example ID with the selected commit. Cherry-pick applies the change relative to that commit's parent; it does not replace every touched file with the source branch's current version. Missing prerequisites can cause conflicts or a build failure even when the patch applies cleanly.

Choose an option for the task

git cherry-pick --no-commit a1b2c3d
git cherry-pick -x a1b2c3d
git cherry-pick 'A^..B'

These are separate alternatives. --no-commit applies changes to the index and working tree for you to inspect or combine before committing. -x records source provenance for supported picks; inspect the final message, especially after resolving conflicts.

A^..B includes A through B for a simple linear sequence where A has a parent. In a graph with merges it is a reachability range, not necessarily a contiguous visual list. Inspect the selected commits first, or provide explicit IDs in dependency order. Root commits have no A^.

Resolve or abandon a conflicted pick

# Edit the conflicted file, then stage its resolved content.
git add -- src/app.js
git cherry-pick --continue
# Alternatively, abandon the active operation:
git cherry-pick --abort

Do not run --abort after a successful continuation unless another operation is still active. Test the result before publishing it.

Understand the history you create

A normal cherry-pick creates a new commit and leaves the source ref unchanged. A matching-parent pick with --ff can fast-forward instead. Later merges still reason about ancestry and file changes; they do not erase duplicate history merely because similar patches exist. Conflicts remain possible when the branches evolve differently.

Rebase is useful when replaying a branch's sequence onto another base. Cherry-pick is useful when choosing particular changes, such as a release backport.

Handle special cases

A merge commit requires -m PARENT_NUMBER to define which parent's view supplies the change. Inspect git show --no-patch --format='%P' COMMIT first; parent one is a workflow convention, not a universal rule. Often the underlying feature commits are easier to backport.

For another repository, add its URL as a remote and fetch the relevant branch. Once the commit object is available locally, it can be cherry-picked, subject to compatible context and licensing or project policy.

See git-cherry-pick.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting