Git
gitgitGuideIntermediate
git cherry-pick — Applying Specific Commits
How to copy specific commits across branches using git cherry-pick: syntax, conflict handling, and backporting bugfixes.
Verified: 2026-09-30
Platforms:
all
#git#cherry-pick#branches#hotfix
git cherry-pick — Applying Specific Commits
git cherry-pick allows you to pick an individual commit from one branch and apply it to your current active branch as a new commit.
1. When to Use Cherry-Pick
- Backporting Hotfixes: You fixed a critical bug on
main, and need to backport that exact patch into a legacyv1.2-releasebranch without merging other experimentalmainfeatures. - Rescuing Work from Abandoned Branches: A team member started a branch with one great utility function, but the rest of the branch was scrapped.
2. Syntax and Usage
# 1. Switch to target branch where you want the commit applied:
git switch release/v1.2
# 2. Cherry-pick the specific commit SHA:
git cherry-pick 7a8b901
# 3. Cherry-pick without creating a commit (stages changes only):
git cherry-pick -n 7a8b9013. Resolving Cherry-Pick Conflicts
If changes conflict with the target branch:
- Git pauses and highlights conflicting files in
git status. - Open files and resolve conflict markers (
<<<<<<</>>>>>>>). - Stage resolved files:
git add <file>. - Continue cherry-pick:
git cherry-pick --continue - Or abort and return to original branch state:
git cherry-pick --abort
Related Topics
git revert — Safe Public History Reversal
How to safely undo commits on shared public branches: creating inverse inverse-diff commits, revert vs reset differences, and reverting merge commits.
Git Tags & Semantic Versioning Releases
Creating and managing Git tags: lightweight vs annotated tags (-a), signing tags (-s), pushing tags to GitHub, and release management.