bashintermediate

Git Cherry-Pick — Apply Specific Commits

Cherry-pick single, multiple, or ranges of commits from other branches without full merge.

bash
# Cherry-pick a single commit
git cherry-pick abc1234

# Cherry-pick multiple specific commits
git cherry-pick abc1234 def5678 ghi9012

# Cherry-pick a range (exclusive start, inclusive end)
git cherry-pick abc1234..def5678

# Cherry-pick a range (inclusive both ends)
git cherry-pick abc1234^..def5678

# Cherry-pick without committing (stage changes only)
git cherry-pick --no-commit abc1234

# Cherry-pick from another remote
git fetch upstream
git cherry-pick upstream/main~3..upstream/main

# If conflicts occur:
git status                    # see conflicted files
# resolve conflicts in your editor, then:
git add .
git cherry-pick --continue

# Abort cherry-pick
git cherry-pick --abort

# Cherry-pick and sign-off
git cherry-pick -s abc1234    # adds Signed-off-by line

Use Cases

  • Backporting hotfixes to release branches
  • Picking features from long-lived branches
  • Applying upstream fixes to forks

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.