Branches & Tags

How to Cherry-Pick a Commit to Another Branch

Apply a specific commit from one branch onto your current branch without merging the entire branch.

Instant 1-Line Solution
Safe CommandIntermediate
git cherry-pick <commit-hash>
When to use this scenario:A bug fix was committed to a feature branch or dev branch, and you need that single fix immediately on production/main.

Step-by-Step Execution Guide

1Switch to target branch
git checkout main

Make sure you are on the destination branch that should receive the commit.

2Cherry pick the commit
git cherry-pick a1b2c3d

Applies the changes from commit a1b2c3d onto your current branch and creates a new commit.

3Cherry pick without automatically committing
git cherry-pick -n a1b2c3d

-n (or --no-commit) stages the changes in your working tree so you can inspect or modify them first.

Critical Pitfalls & Precautions

  • β€’If the cherry-picked commit depends on code changes from earlier commits, merge conflicts may occur.
Frequently Asked Questions

Cherry-Pick a Commit - Frequently Asked Questions

Common questions about safe rollback, remote history implications, and troubleshooting.

Run "git cherry-pick A..B" (applies commits after A up to B) or "git cherry-pick A^..B" (includes commit A).