recovery

git stash

Shelves uncommitted changes onto a stack so you can switch context with a clean working tree. Later, reapply them with pop or apply.

git stash [push | pop | apply | list | drop] [<options>]

Common flags

Flag Purpose
push -m <msg> Stash with an explanatory message
-u / --include-untracked Also stash new untracked files
-a / --all Include ignored files too
pop Reapply the newest stash and remove it from the stack
apply Reapply the stash but keep it in the list
-p / --patch Interactively pick hunks to stash
drop <stash> Delete a specific stash entry

Examples

git stash push -m "WIP header refactor"

Save labeled work-in-progress

git stash pop

Reapply and remove the latest stash

git stash list

Show all stash entries with their messages

Gotcha

Untracked files are NOT stashed unless you pass -u; without it, new files stay in your working tree and may block a checkout.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge