How to cherry-pick commits in Git
Git cherry-pick applies specific commits from one branch to another without merging the entire branch history.
As the creator of CoreUI with over 25 years of version control experience since 2000, I’ve used cherry-pick to backport bug fixes to older release branches and bring specific features into hotfix branches.
The standard approach identifies the commit hash with git log and applies it with git cherry-pick.
This gives surgical control over which changes move between branches.
Apply a single commit to the current branch.
git log --oneline feature-branch
# abc1234 Fix login validation bug
# def5678 Add new dashboard widget
git checkout main
git cherry-pick abc1234
Find the commit hash with git log. Switch to the target branch. cherry-pick applies that commit’s changes as a new commit. The commit message is preserved but the hash is different.
Cherry-Pick Multiple Commits
Apply a range of commits at once.
git cherry-pick abc1234 def5678 ghi9012
git cherry-pick abc1234^..ghi9012
List individual hashes for non-consecutive commits. Use ^.. range syntax for consecutive commits. The ^ includes the first commit in the range. All selected commits apply in order.
Handling Cherry-Pick Conflicts
Resolve conflicts during cherry-pick.
git cherry-pick abc1234
# CONFLICT: merge conflict in src/auth.js
# Edit the conflicted file to resolve
git add src/auth.js
git cherry-pick --continue
# Or abort if something is wrong
git cherry-pick --abort
When cherry-pick finds conflicts it pauses like a merge. Resolve the conflict manually, stage the file, then --continue. Use --abort to cancel and return to the pre-cherry-pick state.
Cherry-Pick Without Committing
Stage the changes without creating a commit.
git cherry-pick --no-commit abc1234
git cherry-pick --no-commit def5678
git diff --staged
git commit -m "Backport login fix and validation update"
--no-commit applies the changes to the working tree without committing. Apply multiple cherry-picks then commit them together. This is useful for combining several small commits into one on the target branch.
Cherry-Pick to Another Remote Branch
Apply commits across forks or remotes.
git fetch upstream
git log upstream/main --oneline
git cherry-pick upstream-commit-hash
Fetch from the remote to access its commits. Use the commit hash from git log on the remote branch. The commit applies locally and can be pushed to your fork.
Best Practice Note
This is the same cherry-pick workflow we use for CoreUI hotfix releases when backporting bug fixes to older supported versions. Cherry-pick creates a new commit with a new hash - the two branches diverge. This is intentional and expected. Avoid cherry-picking the same commit repeatedly across many branches as it creates confusing parallel histories. If you need to apply the same change to many branches, consider a merge or rebase instead. Always test after cherry-picking - subtle context differences can cause bugs even when there are no conflicts.



