Git cherry-pick allows you to apply a specific commit from one branch to another without merging the entire branch. It is commonly used to move bug fixes, small improvements, or urgent patches across branches such as development, staging, and production.
Instead of merging all changes from a branch, git cherry-pick selectively copies only the commits you need, making it a powerful tool for maintaining a clean Git history. You can also compare this approach with
git merge or
git rebase.
Git Cherry Pick Cheat Sheet (Commands + Examples)
If you only need to copy a bug fix from one branch to another without merging the entire branch, git cherry-pick is the safest and fastest option.
| Description | Command |
|---|---|
| Cherry pick a single commit from another branch | git cherry-pick <commit-hash> |
| Cherry pick multiple specific commits | git cherry-pick hash1 hash2 |
| Cherry pick a range of commits between two commit hashes | git cherry-pick A^..B |
| Cherry pick a commit referenced from another branch | git cherry-pick feature-branch~2 |
| Resume cherry-pick after resolving conflicts | git cherry-pick --continue |
| Cancel the current cherry-pick operation and restore branch state | git cherry-pick --abort |
| Skip the commit that is causing a conflict | git cherry-pick --skip |
| Apply changes from a commit without automatically creating a commit | git cherry-pick --no-commit |
| Edit the commit message during cherry pick | git cherry-pick -e <commit-hash> |
| Review commit changes before applying them | git show <commit-hash> |
| Cherry pick a commit from a remote branch | git cherry-pick origin/branch~1 |
| Cherry pick and add a Signed-off-by line | git cherry-pick -s <commit-hash> |
| Resolve conflicts automatically using a merge strategy | git cherry-pick -X theirs <commit> |
| Verify commit history before selecting a commit | git log --oneline |
Cherry Pick a Single Commit
Sometimes you may want to move a specific bug fix or small change from one branch to another without merging the entire branch. This is one of the most common use cases for git cherry-pick.
Identify the commit hash
First, find the commit you want to copy to another branch.
You can view recent commits using git log:
git log --onelineExample output:
d4f3e5b Fix login validation bug
a7c8e2f Improve API response handling
b9d0e3g Add new feature toggleThe short string at the beginning (d4f3e5b) is the commit hash that Git uses to reference the commit.
Apply commit to another branch
Switch to the branch where you want to apply the commit using git checkout or git switch.
git checkout mainThen run the cherry-pick command:
git cherry-pick d4f3e5bGit will apply the changes from that commit onto the current branch.
A new commit will be created on the target branch with the same changes but a different commit hash.
Cherry Pick Multiple Commits
Cherry pick multiple commit hashes
You can apply multiple commits in one command by listing their hashes.
git cherry-pick a7c8e2f b9d0e3g c1f2h3iGit will apply the commits in the order provided.
This is useful when a series of fixes or improvements needs to be moved to another branch.
Cherry pick a range of commits
If the commits are sequential, you can cherry-pick a range.
git cherry-pick a7c8e2f^..d4f3e5bExplanation:
a7c8e2f^includes the starting commitd4f3e5bis the final commit in the range
This applies all commits between those two points.
Cherry Pick a Commit from Another Branch
Cherry-picking is commonly used to move changes from a feature branch to another branch such as main, release, or hotfix.
Cherry pick from feature branch to main
First switch to the target branch:
git checkout mainThen apply the commit from the feature branch:
git cherry-pick feature-branch~1Alternatively, you can cherry-pick using the commit hash obtained from the feature branch.
Cherry pick from remote branch
You can also cherry-pick commits from a remote branch after fetching the latest updates using git fetch.
git fetch originThen run:
git cherry-pick origin/feature-branch~1This applies the selected commit from the remote branch to your current branch.
Resolve Cherry Pick Conflicts
During a cherry-pick operation, Git attempts to apply changes from the selected commit to the current branch. If the same lines of code were modified differently in the target branch, Git cannot automatically merge them and raises a conflict.
Why conflicts occur during cherry pick
Conflicts typically happen when:
- The same file was modified in both branches
- The target branch has diverged significantly
- The cherry-picked commit depends on earlier commits not present in the target branch
Git will pause the operation and display a message similar to:
error: could not apply d4f3e5b... Fix login validation bugYou can check conflicting files using git status.
git statusManually edit the files to resolve the conflict.
Continue cherry pick after conflict
After resolving the conflicts in the affected files, stage the changes and continue the cherry-pick process using git add.
git add .
git cherry-pick --continueGit will then create the new commit on the current branch with the resolved changes.
Abort cherry pick operation
If you decide not to proceed with the cherry-pick operation, you can cancel it.
git cherry-pick --abortThis command restores the branch to the state it was in before the cherry-pick started.
Cherry Pick Without Commit
Sometimes you may want to apply the changes from a commit but review or modify them before creating a new commit.
Use git cherry-pick --no-commit
The --no-commit option applies the changes without automatically creating a commit.
git cherry-pick --no-commit <commit-hash>This allows you to inspect or modify the changes before committing them.
Modify changes before committing
After applying the changes, you can edit files as needed and then create a commit manually using git commit.
git add .
git commit -m "Apply selected changes from commit"This gives you full control over the final commit content and message.
Common Git Cherry Pick Errors
When using git cherry-pick, developers may encounter common errors related to commit history or conflicts.
cherry-pick already applied
This error appears when Git detects that the selected commit changes already exist in the target branch.
Example message:
The previous cherry-pick is now emptyPossible causes:
- The commit was already merged
- The same changes were applied earlier
In such cases you can skip the commit using git cherry-pick --skip, or review history using
git reflog.
git cherry-pick --skipcherry pick conflict
If Git cannot automatically merge the commit changes, it will stop and mark the conflicting files.
Example message:
CONFLICT (content): Merge conflict in file.txtSteps to resolve:
- Edit the conflicting files
- Remove the conflict markers
- Stage the resolved files
- Continue the cherry-pick
git add .
git cherry-pick --continuecommit not found
This error occurs when Git cannot locate the specified commit hash.
Example message:
fatal: bad revision '<commit-hash>'Possible reasons:
- Incorrect commit hash
- Commit exists only in another branch
- Remote branch was not fetched
You can verify available commits using git log.
git log --onelineor fetch remote updates:
git fetch originFrequently Asked Questions
1. What is git cherry pick used for?
The git cherry-pick command allows you to select a specific commit from one branch and apply it to another branch without merging the entire branch.2. How do I cherry pick a commit in Git?
First identify the commit hash usinggit log, then run git cherry-pick <commit-hash> on the target branch where you want to apply the commit.3. Can I cherry pick multiple commits in Git?
Yes. You can cherry-pick multiple commits by specifying multiple commit hashes or by using a commit range such asgit cherry-pick A^..B.4. How do I resolve conflicts during git cherry pick?
Resolve the conflicts manually, stage the resolved files usinggit add, and then continue the process using git cherry-pick --continue.5. How do I abort a cherry pick operation?
If a cherry-pick operation is in progress and you want to cancel it, rungit cherry-pick --abort. This restores the branch to its previous state before the cherry-pick began.Summary
The git cherry-pick command allows developers to selectively apply commits from one branch to another without merging the entire branch. This makes it particularly useful for transferring bug fixes, hotfixes, or small improvements across branches such as development, staging, and production.
Understanding how to cherry-pick commits, resolve conflicts, and manage commit history helps maintain a clean and organized Git workflow. For recovery scenarios, see git reset.



![Git Error: Cannot Delete Branch Checked Out or Used by Worktree [SOLVED]](/cannot-delete-branch-checked-out-at/git-cannot-delete-branch_hu_3f86bd25a59d627d.webp)






