Script Valley
Git and GitHub Complete Course: From Beginner to Advanced
Intermediate Git: Stashing, Tagging, Reverting, and ResettingLesson 4.5

Cherry-Picking Commits

git cherry-pick, apply specific commit, cherry-pick range, cherry-pick use cases, conflicts during cherry-pick

Cherry-Picking Commits

Cherry-picking applies the changes from a specific commit (or range of commits) onto the current branch without merging the entire source branch. It is used for targeted backporting of fixes and transferring isolated changes between branches.

Diagramgit cherry-pick Targeted Commit Transfer

IMAGE PROMPT (replace this block with your generated image):

Flat branch-to-branch transfer diagram on white background. Title: git cherry-pick — Apply a Specific Commit. Two horizontal branch tracks stacked vertically. Top track: feature/payment branch. Commits: C1 → C2 → F1 → F2 (bug fix) → F3. F2 has a star badge labeled Critical bug fix — hash: abc1234. Bottom track: release/v1.1 branch (branched from C2). Commits: C1 → C2 → R1 → R2. A curved arrow from F2 on the top track sweeps down to land after R2 on the bottom track, creating a new commit F2' (prime notation). F2' has a badge: Same changes, new hash in #3A5EFF. Command badge at the curve: git cherry-pick abc1234 in #3A5EFF pill. Three use-case labels on the right side: 1. Backport hotfix to release branch (current scenario shown). 2. Rescue commit made on wrong branch. 3. Apply one useful commit from abandoned feature. Conflict resolution note: git cherry-pick --abort or --continue. White background, brand color #3A5EFF for cherry-pick arrow and F2' badge.

Basic Cherry-Pick

git cherry-pick abc1234

This takes the changes introduced by commit abc1234 and applies them as a new commit on your current branch. The new commit has a different hash but the same changes and message as the original.

Cherry-Picking a Range

git cherry-pick abc1234..def5678

This applies all commits from (but not including) abc1234 up to and including def5678.

Cherry-Pick Without Committing

git cherry-pick --no-commit abc1234

This applies the changes to the working directory and staging area but does not create a commit. Useful when you want to combine changes from multiple cherry-picks into one commit.

Common Use Cases

Cherry-pick is ideal for: backporting a critical bug fix from a development branch to a release branch, applying a single useful commit from a feature branch that was abandoned, and recovering a commit that was accidentally made on the wrong branch.

Handling Conflicts

If a conflict occurs during cherry-pick, resolve it just like a merge conflict: edit the file, remove conflict markers, stage it, then run git cherry-pick --continue. Use git cherry-pick --abort to cancel.