Git Cherry-Pick Commits Example
Apply specific commits from one branch to another using cherry-pick with conflict resolution.
# Cherry-pick a single commit by hash
git cherry-pick abc1234
# Cherry-pick multiple commits
git cherry-pick abc1234 def5678 ghi9012
# Cherry-pick a range of commits (exclusive start)
git cherry-pick abc1234..ghi9012
# Cherry-pick without committing (stage changes only)
git cherry-pick --no-commit abc1234
# Cherry-pick from another branch
git checkout main
git cherry-pick feature/hotfix~2
# If conflicts occur:
git add .
git cherry-pick --continue
# Abort cherry-pick
git cherry-pick --abort
# Cherry-pick and edit the commit message
git cherry-pick -e abc1234
# Find the commit hash to cherry-pick
git log --oneline other-branch | head -10Use Cases
- Backporting bug fixes to release branches
- Selectively applying features across branches
- Hotfix deployment without full merge
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.
Git Worktree for Multiple Branches
Work on multiple branches simultaneously using git worktree without stashing or switching.
Undo Last Git Commit (Soft and Hard)
Git commands to undo the last commit while keeping changes staged, unstaged, or fully discarded.
Squash Multiple Git Commits
Interactive rebase to squash multiple commits into one clean commit before merging a feature branch.