Using Git Cherry-pick
This article was last updated on: May 17, 2026 am
Overview
Regardless of project size, handling changes across multiple Git branches can become difficult when you’re working with a group of programmers. Sometimes, rather than merging an entire Git branch into another, you’d prefer to pick and move just a few specific commits. This process is known as “cherry-picking.”
This article covers the what, why, and how of cherry-picking.
Let’s get started~
What Is Cherry-pick?
With the cherry-pick command, Git can merge selected commits from any branch into the current Git HEAD branch.
When performing git merge or git rebase, all commits from a branch are merged. The cherry-pick command, however, allows you to select individual commits for integration.
The difference is illustrated below:

△ Using merge: When performing a merge or rebase, all commits from a branch are integrated.

△ Using cherry-pick: Allows you to select individual commits for integration. In this example, only C2 is integrated into the main branch, not C4.
Why Use Cherry-pick?
The following scenario may help illustrate the purpose of cherry-picking.
Imagine you’re implementing a new feature for an upcoming weekly sprint. Once the code is ready, you push it to a remote branch for testing.
However, the client isn’t happy with all the changes and asks you to deliver only certain modifications. Since the client hasn’t approved all the changes for the next release, git rebase won’t produce the desired result — because git rebase or git merge would incorporate all adjustments from the previous sprint.
Cherry-pick solves this problem! Since cherry-pick only focuses on the changes added in a commit, it brings in only the approved changes without adding other commits.
There are several other reasons to use cherry-pick:
- It’s essential for bug fixes, since bugs in development branches are tied to their specific commits.
- By using git cherry-pick instead of other options for applying specific commit changes (such as git diff), you can avoid unnecessary conflicts.
- It’s a useful tool when a full branch merge isn’t possible due to version incompatibilities between Git branches.
When to Use Cherry-pick?
In short: as sparingly as possible. The reason to minimize cherry-pick usage is that it easily creates “duplicate” commits: when you cherry-pick a commit into the HEAD branch, Git must create a brand-new commit with identical content. However, this is an entirely new commit object with its own SHA identifier. You also lose the ability to track commit history.
If you cherry-pick many commits out of order, they’ll be recorded in your branch, which can lead to undesirable results in your Git branch.
Whenever you can use a traditional merge or rebase for integration, you should do so. Cherry-pick should be reserved for situations where that isn’t possible — for example, when you need to create a hotfix or want to salvage one or a few commits from an abandoned branch.
How to Use the Cherry-pick Command?
Process Overview
Here are the steps:
- Pull the local branch. Use git fetch.
- Switch to the branch you want to merge into. You’d typically do this by running git checkout main.
- Find the commits you want to pull into the branch. Go to git log and get the unique commit hash for each commit.
- Cherry-pick the commits you want to add to the branch. Run the following command: git cherry-pick
. This will pull only that commit into the current branch. - (Optional) In some cases, you may need to resolve conflicts manually.
- Push the branch as usual: git push origin main.
Specific Commands
In its simplest form, the cherry-pick command only requires the SHA identifier of the commit you want to integrate into the current HEAD branch.
To get the commit hash, use the git log command:
1 | |
Once you know the commit hash, you can use the cherry-pick command.
The syntax is:
1 | |
│ 📝Notes:
│
│
For example:
1 | |
This will apply the specified change exclusively to the currently checked-out branch.
If you want to make further modifications, you can also instruct Git to add the commit changes to your working copy without committing.
The syntax is:
1 | |
For example:
1 | |
If you want to cherry-pick multiple commits at once, add their commit hashes separated by spaces:
1 | |
When cherry-picking commits, you cannot use git pull, because it fetches commits from a repository and automatically merges them into another. The cherry-pick command is specifically designed to avoid this; use git fetch instead, which fetches commits without applying them.
Cherry-pick in Practice
To try the process, launch a terminal and create a sample project:
1 | |
Create some data and commit it:
1 | |
Now, create a fork of the project to represent a remote developer:
1 | |
This is a valid commit. Now, create a bad commit representing something you don’t want to merge into the project:
1 | |
Return to your authoritative repository and fetch the commits from your hypothetical developer (using git fetch):
1 | |
1 | |
You’ve fetched the commits from the hypothetical developer but haven’t merged them into your repository yet. You want to accept the second commit but not the third, so use cherry-pick:
1 | |
Now the second commit is in your repository:
1 | |
Push the changes to the remote server, and you’re done!
Cherry-picking Multiple Commits in Practice
Cherry-pick several commits from dev for merging:
1 | |
The first merge may encounter a conflict. Resolve it manually and git add the specific files or git rm them.
Continue the cherry-pick:
1 | |
The second commit may have no conflicts and merge directly.
The third commit may have conflicts again. Resolve them manually and git add the specific files or git rm them.
Continue the cherry-pick:
1 | |
Finally, running git cherry-pick --continue again will indicate that there are no tasks in progress.
At this point, you can push:
1 | |
Summary
Cherry-pick is a powerful command that can cause trouble if you don’t properly understand what might happen. However, when you mess up and commit to the wrong branch, it can save your life (or at least your workday).