Git Stash

Shelve dirty work, switch context, and restore it later.

  • git stash
  • stash pop
  • stash untracked
  • stash list
  • stash apply

Git Stash

Shelve dirty work, switch context, and restore it later.

Commands

CommandWhat it does
git stash push -m "wip"Stash tracked changes with a label
git stash push -u -m "wip"Include untracked files in the stash
git stash listList all stashes
git stash popRestore and drop the latest stash
git stash apply stash@{1}Restore a specific stash, keep it stored
git stash drop stash@{0}Delete a stash entry

Example

git stash push -u -m "half-done search"
git switch main && git pull
git switch - && git stash pop

FAQ

stash pop vs apply?

pop restores and deletes the entry; apply restores but keeps it, safer when unsure.

Where did my stashed files go?

They are commit-like objects in .git/refs/stash; git stash list shows every entry.

SSS

stash pop vs apply?
pop restores and deletes the entry; apply restores but keeps it, safer when unsure.
Where did my stashed files go?
They are commit-like objects in .git/refs/stash; git stash list shows every entry.

Git