Apply specific commits from one branch to another without merging everything.
git cherry-pick allows you to:
Take a specific commit from one branch and apply it to another branch.
Scenario:
You fixed a bug in develop
But production needs the same fix urgently
Instead of merging entire branch:
👉 Use cherry-pick to bring ONLY that commit
flowchart LR
A[Branch A] --> B[Commit X]
B --> C[Cherry Pick]
C --> D[Branch B]
main: A --- B --- C
\
feature: D --- E (fix commit)
Cherry-pick E → main
Result:
main: A --- B --- C --- E'
👉 E' = new commit (copy of E)
git cherry-pick <commit-hash>Cherry-pick does NOT move commit.
It creates a new commit with same changes.
git log1. Bug fixed in feature branch
2. Production needs fix
3. Cherry-pick commit
4. Deploy fix
git checkout maingit cherry-pick abc123New commit added to main
git cherry-pick commit1 commit2 commit3git cherry-pick A^..DIf changes overlap:
git cherry-pick abc123May result in:
CONFLICT (content): Merge conflict
# resolve manually
git add .
git cherry-pick --continue1. Git takes commit changes
2. Applies diff to current branch
3. Creates new commit
Commit (source branch)
↓
Diff extracted
↓
Applied to target branch
↓
New commit created
| Cherry-Pick | Merge |
|---|---|
| specific commits | full branch |
| creates new commit | combines history |
| precise | broader |
| Cherry-Pick | Rebase |
|---|---|
| select commits | replay full branch |
| manual | automatic sequence |
Cherry-pick creates new commit → duplicates possible.
Commit may depend on earlier commits.
Can create messy history.
- use for hotfixes
- use for small changes
- avoid large features
- understand dependencies
- test after applying
- hotfix in production
- applying patch across branches
- backporting changes
- selective bug fixes
Apply a specific commit from one branch to another.
No, it copies changes and creates new commit.
For selective changes, hotfixes, or backports.
Resolve manually and continue.
# create commit in branch
git checkout -b feature
echo "fix" >> file.txt
git commit -am "Fix bug"
# go to main
git checkout main
# cherry-pick
git cherry-pick <commit-hash>Cherry-pick is a precision tool.
Use it when you need:
- exact change
- quick fix
- minimal impact
➡️ 03-git-reflog.md