Git Cherry-pick
Last updated
git cherry-pick copies the changes from one or more specific commits and applies them onto your current branch as new commits. It's how you grab a single fix from another branch without merging that whole branch - useful for backporting a hotfix or pulling one commit out of a feature branch.
Try these in the terminal playground - a real shell in your browser, nothing to install.
Syntax
| Command | What it does |
|---|---|
git cherry-pick <hash> | Apply one commit onto the current branch |
git cherry-pick <a> <b> | Apply several commits in order |
git cherry-pick <a>..<b> | Apply a range of commits (excluding a) |
git cherry-pick -n <hash> | Apply the changes but don't commit yet |
git cherry-pick -x <hash> | Note the original commit in the message |
During a cherry-pick
If a cherry-pick hits a conflict, resolve it and continue.
| Command | What it does |
|---|---|
git cherry-pick --continue | Resume after resolving conflicts |
git cherry-pick --abort | Cancel and restore the branch |
git cherry-pick --skip | Skip the current commit |
Worked example
| Step | Command | Result |
|---|---|---|
| 1 | git log --oneline hotfix | Find the hash of the fix, for example a1b2c3d |
| 2 | git switch main | Move to the branch that should receive the fix |
| 3 | git cherry-pick a1b2c3d | Applies the fix to main as a new commit with a new hash |
Git cherry-pick FAQ
What does git cherry-pick do?
It takes the changes introduced by a specific commit and applies them onto your current branch as a brand-new commit (with a new hash). Unlike merge or rebase, it doesn't bring over a whole branch - just the commit or commits you name.
When should I use cherry-pick?
Use it when you need one particular commit somewhere else - for example, backporting a bug fix from
main to a release branch, or pulling a single useful commit out of a feature branch without merging everything. If you want the entire branch, use merge or rebase instead.How do I cherry-pick multiple commits?
List them:
git cherry-pick <a> <b> <c> applies each in order. For a contiguous range use git cherry-pick <start>..<end>, which applies every commit after start up to and including end. Add <start>^..<end> if you want to include start itself.What if a cherry-pick causes a conflict?
Git pauses and marks the conflicted files. Resolve them,
git add the results, then run git cherry-pick --continue. To back out entirely, use git cherry-pick --abort, which restores your branch to the state before the cherry-pick started.How do I cherry-pick a commit from another branch?
Find the commit's hash with
git log --oneline <other-branch>, switch to the branch that should receive it, and run git cherry-pick <hash>. You can also pass a branch name, as in git cherry-pick feature, which picks the commit at the tip of that branch.What is the difference between cherry-pick and merge?
git merge brings over every commit on a branch and records where the histories joined. Cherry-pick copies only the commits you name, as new commits, with no link back to the originals. Merge the branch when you want all of it; cherry-pick when you want one or two commits.
Can I practice this online?
Yes. Open the terminal playground to run
git cherry-pick in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers moving commits between branches step by step.