Cherry-pick and stash
What this lesson covers
Section titled “What this lesson covers”L11 introduces two surgical tools every working developer reaches for: cherry-pick (copy a single commit from one branch onto another) and stash (set aside in-progress work without committing).
Cherry-pick is the canonical backport tool. When a fix lives on main and also needs to be on release/v1.4, you cherry-pick the fix commit onto the release branch. One command, one new commit, traceable via the -x flag.
Stash is the safety net for context switches. When you’re mid-work and need to swap branches urgently (hotfix, demo, code review), stash saves your in-progress work and resets the working tree to clean. Later, you pop the stash to restore.
Both tools feel “advanced” the first time and routine by the tenth. Both are reversible. Both have small gotchas worth knowing (duplicate cherry-picks, lost stashes, conflicts during apply).
By the end of L11, the reader will be able to
Section titled “By the end of L11, the reader will be able to”- Explain what cherry-pick does mechanically (copy a commit’s diff onto the current branch as a new commit) and when to reach for it
- Apply
git cherry-pick <sha>to backport a hotfix from main to a release branch, with the-xflag for traceability - Recognize cherry-pick conflicts and recover using
--continue,--skip, or--abort - Use
git stash push -m "..."to save work-in-progress with a descriptive message - Choose between
git stash pop,git stash apply, andgit stash branchfor different recovery situations - Identify when stash is wrong (multi-day pauses, hand-off to teammates, anything high-value) and substitute a WIP commit on a branch instead
- Identify when cherry-pick is wrong (all of branch X onto branch Y; commits with subtle dependencies) and substitute a merge instead
Prerequisites
Section titled “Prerequisites”L1-L10 of T7. Specifically: you should already understand commits as snapshots (L3), branches (L5), how to switch branches (L5), and how merge conflicts work (L7). Cherry-pick conflicts use the same resolution process as merge conflicts.
Reading map
Section titled “Reading map”- 1: motivation scenario (3:14pm hotfix backport, the “you could re-implement OR cherry-pick” moment)
- 2: cherry-pick mechanics, what it copies, what it creates, the SHA story
- 3: cherry-pick commands (single, multiple, range, —no-commit, -x)
- 4: cherry-pick conflict resolution (continue, skip, abort)
- 5: when cherry-pick is right vs wrong
- 6: stash mechanics, what it saves, where it goes
- 7: stash commands (push, list, pop, apply, drop, clear, show)
- 8: stash branch, the “stash from three weeks ago” recovery
- 9: stash conflict handling
- 10: when stash is wrong (multi-day work, high-value WIP)
- 11: the common “boss just paged me” pattern
- 12: the common backport pattern
- 13: four worked examples (multi-LTS backport, swap-branches stash, abandoned experiment cherry-pick, stash branch recovery)
- 14: SVN/Mercurial/Perforce comparisons for experienced devs
- 15: a useful frame for managers and TPMs
- 16: Phase 4 foreshadowing (cherry-pick is the multi-agent transport mechanism)
- 17: four team-scale scenarios (startup, 50-person, OSS LTS, multi-agent)
- 18: stay-calm psychology
- 19: closers and voice anchor
What this lesson deliberately does not cover
Section titled “What this lesson deliberately does not cover”- Interactive rebase (
git rebase -i), covered in L12, which goes deeper on rebase patterns - Worktrees (
git worktree add), covered in L13, the entry point for Phase 4 multi-agent - Filter-branch or git-filter-repo for rewriting bulk history, out of scope for T7
- Cherry-pick of merge commits (
-mflag), mentioned but not drilled, edge case for most users - Patches as transport (
git format-patchandgit am), historical alternative to cherry-pick, rarely used today
Estimated reading + practice time
Section titled “Estimated reading + practice time”55-75 minutes for the lesson body, plus 30-40 minutes for the practice drills. Most learners spend the most time on the cherry-pick conflict handling section, it’s the part most often hit in real work.