Git stash is your safety net

·cheatly.dev

You're mid-feature, files half-changed, and someone asks you to look at a bug on another branch. You can't switch branches with uncommitted changes. You don't want to commit half-finished work. This is exactly what git stash is for.

The basic workflow

Stash Essentials
git stash
Save all uncommitted changes and clean the working tree
git stash pop
Restore the most recent stash and remove it from the list
git stash list
See all stashed changes
git stash apply
Restore the most recent stash but keep it in the list
git stash drop
Delete the most recent stash

The typical flow:

  1. git stash — your changes disappear, working tree is clean
  2. Switch branches, fix the bug, commit, switch back
  3. git stash pop — your changes are back exactly where you left them

Stashing specific things

Targeted Stashing
git stash -u
Include untracked (new) files
git stash -m "message"
Stash with a description so you remember what it was
git stash push path/to/file
Stash only specific files
Always use git stash -u if you have new files. Without -u, untracked files get left behind — you stash your changes but the new files stay in your working directory, which is almost never what you want.

Managing multiple stashes

Stashes stack up. The most recent is stash@{0}, the one before is stash@{1}, etc.

Working with the Stack
git stash list
See all stashes with their index and message
git stash show stash@{1}
See what changed in a specific stash
git stash pop stash@{2}
Restore a specific stash (not just the latest)
git stash clear
Delete all stashes (careful!)
If you find yourself with more than 2-3 stashes, you're probably better off committing to a temporary branch instead. Stashes are great for quick context switches, not long-term storage.

Stash in lazygit

If you use lazygit, stashing is even faster: press 5 to open the Stash panel, Space to apply, g to pop, d to drop. Visual and immediate.

For the full reference, see our git cheatsheet and lazygit cheatsheet.