---
title: "How do I cherry-pick a commit from another branch?"
description: "Copy one commit, or a range of commits, from another branch onto your current branch with git cherry-pick, and handle conflicts, merges and duplicate commits."
url: https://www.danny.engineering/answer/git/how-do-i-cherry-pick-a-commit-from-another-branch
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:57:00.000Z
tags: ["Git"]
---

# How do I cherry-pick a commit from another branch?

## The short answer


Switch to the branch that should receive the change, find the commit's hash on the other branch, and run `git cherry-pick` with that hash. Git applies the same change as a new commit on your current branch.


```bash
git switch main
git log --oneline feature/payments     # find the commit you want
git cherry-pick 4f2c9a1
```


## Why it happens


Sometimes you need one specific change without merging a whole branch. Common cases are a bug fix made on a feature branch that also needs to go to `main`, or a fix on `main` that needs to go back to a release branch.


`git cherry-pick` works out the diff that a commit introduced compared with its parent, then applies that diff on top of your current branch and commits it. The new commit has the same message and author but a different hash, because its parent is different. Git treats it as a separate commit from the original.


## How to fix it


### Pick a single commit


```bash
git switch release/2.3
git cherry-pick 4f2c9a1
```


It is good practice to add `-x`. It appends a line such as "(cherry picked from commit 4f2c9a1...)" to the message, so anyone reading the history can trace where it came from:


```bash
git cherry-pick -x 4f2c9a1
```


### Pick several commits or a range


List hashes to apply them in order:


```bash
git cherry-pick 4f2c9a1 b71e0d3 9a0c442
```


For a run of consecutive commits, use a range. `A..B` means "everything after A, up to and including B", so add `^` to include A itself:


```bash
git cherry-pick 4f2c9a1^..9a0c442
```


### Apply the change without committing


`-n` (or `--no-commit`) applies the changes to your working tree and index but stops before committing. That is useful for combining several picks into one commit or adjusting the change first:


```bash
git cherry-pick -n 4f2c9a1 b71e0d3
git commit -m "Backport payment rounding fixes"
```


### Handle conflicts


If the change does not apply cleanly, Git stops and marks the conflicting files, just as in a merge.


```bash
git status                      # see the conflicted files
# edit the files and remove the conflict markers
git add src/payments.ts
git cherry-pick --continue
```


You can also give up with `git cherry-pick --abort`, which returns the branch to how it was before you started, or skip just the current commit in a sequence with `git cherry-pick --skip`.


### Cherry-pick a merge commit


A merge commit has two parents, so Git does not know which side's changes you want. Tell it with `-m` and the parent number, where `1` is usually the branch that was merged into:


```bash
git cherry-pick -m 1 c3d7e88
```


## Common pitfalls

- Cherry-picking a commit that depends on earlier commits you did not pick. It may conflict or apply but leave code that does not build.
- Cherry-picking and then later merging the same branch. Git usually notices identical changes, but if the code has moved on you can get confusing conflicts or a change applied twice.
- Using cherry-pick to move lots of work between branches. If you need most of a branch, a merge or rebase keeps history clearer.
- Expecting the same commit hash. The new commit always has a new hash.
- Leaving out `-x` on shared branches, which makes it harder to see later that a fix was backported.

## Related reading

- [Git documentation: git cherry-pick](https://git-scm.com/docs/git-cherry-pick)
