bashintermediate

Git Cherry-Pick Commits Example

Apply specific commits from one branch to another using cherry-pick with conflict resolution.

bash
# 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 -10

Use 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.