Skip to content

Summary: Cherry-pick and stash

Cherry-pick copies a single commit’s diff onto your current branch as a new commit. Stash saves your in-progress working tree changes so you can switch context cleanly.

  • git cherry-pick abc1234, apply commit abc1234 to current branch as a new commit
  • git cherry-pick -x abc1234, add traceability line to the new commit message (recommended)
  • git cherry-pick --continue, after resolving conflicts
  • git cherry-pick --abort, give up, restore original state
  • git cherry-pick abc..def, range (exclusive of abc); use abc^..def to include abc

Right tool for: hotfix backports, forward-ports, salvage from abandoned branches. Wrong tool for: full branch merges, commits with subtle dependencies, branches that will merge anyway.

  • git stash push -m "WIP descriptive message", save with a name
  • git stash list, see all stashes
  • git stash show -p stash@{0}, see the diff of a stash
  • git stash pop, apply most recent and remove from stack
  • git stash apply, apply most recent, keep on stack
  • git stash drop stash@{N}, remove a specific stash
  • git stash branch new-branch stash@{0}, create branch from where you were, apply stash there

Right tool for: short context switches (minutes to a few hours), branch swaps, quick experiments. Wrong tool for: multi-day pauses, hand-offs to teammates, high-value WIP. Commit to a branch instead.

  • Don’t cherry-pick the same commit twice onto the same branch, it creates duplicate commits.
  • Don’t use git stash clear casually, you may lose work.
  • Don’t let stashes pile up, visible in git stash list, easy to forget what’s in them.
  • Don’t treat stash as a backup, it’s local-only, not pushed, not visible to teammates.

Git stores snapshots. Every other command is just navigating those snapshots.

Cherry-pick takes the diff between two snapshots and replays it. Stash packages a working-tree-vs-HEAD diff as a snapshot you can restore later. No magic.

L12 (Rebase, deeper) revisits rebase with a heavier focus on history cleanup: git rebase -i for interactive rebase, fixup and squash to combine related commits, and the line between safe rebases (local branches) and dangerous ones (published history). The cherry-pick mental model (copying commits to a new base) is the same engine that rebase uses under the hood, so L11 sets up L12.