TLDR: git stash to save, git stash pop to restore. Use -m "message" if you’ll have multiple stashes.
I needed to switch branches but had uncommitted changes. Git stash saves them temporarily.
Basic workflow Link to heading
Stash current changes:
git stash
Apply and remove from list:
git stash pop
That’s 90% of my stash usage.
Named stashes Link to heading
Stash with a message:
git stash push -m "half-finished auth refactor"
I always name my stashes now. I’ve lost work by having a pile of unnamed stashes like stash@{0}, stash@{1}, etc., then forgetting which was which and accidentally dropping the wrong one.
List stashes:
git stash list
Apply a specific stash:
git stash apply stash@{2}
Other commands Link to heading
Stash specific files:
git stash -- src/file.ts
Apply most recent stash (keeps it in the list):
git stash apply
Drop a stash:
git stash drop stash@{0}
Clear all stashes (careful - no confirmation):
git stash clear
Avoiding lost work Link to heading
Stashes feel temporary, but they can accumulate. I’ve had stashes sitting around for weeks, then accidentally cleared them. A few tips:
- Name your stashes -
git stash push -m "description" - Don’t let stashes pile up - if it’s been more than a day, commit it to a branch
- Check before clearing - run
git stash listbeforegit stash clear
For longer-lived work, consider creating a WIP branch instead of stashing. Alternatively, git worktrees eliminate the need to stash altogether.