git stash — More Than a Panic Save (Partial Stash, Named Stashes, and the Rest)
Beyond the panic save: named stashes, stash list, show -p, partial stash with --patch, apply vs pop, and the untracked files gotcha you’ll hit eventually.
You learned git stash in a panic. Someone pinged you mid-feature, you needed to switch branches immediately, and stash was the fastest exit. Saved the day.
Then you had three stashes, forgot what was in them, popped the wrong one onto the wrong branch, and decided stash was broken. It’s not broken. You just need a handful more commands.
The untracked files gotcha (read this first)
git stash only saves tracked files — files already known to git. New files you haven’t staged are invisible to it.
# You created a new file mid-feature
echo "temp work" > new-feature.js
git stash
# new-feature.js is still sitting there — stash ignored it entirely
Add -u to include untracked files:
git stash push -u
There’s also -a (--all) which includes ignored files too. That’s almost never what you want — it’ll stash your node_modules changes and .env files and make restoring a nightmare.
Name your stashes before you regret it
The default stash message is:
stash@{0}: WIP on main: a3f1c2d Update dependencies
That’s meaningless when you have three stashes from three different half-finished features. Use git stash push -m to name them:
git stash push -u -m "wip: oauth token refresh flow"
git stash push -u -m "experiment: lazy load images on scroll"
git stash push -u -m "fix: header z-index issue"
Now git stash list is actually readable:
stash@{0}: On main: fix: header z-index issue
stash@{1}: On feature/images: experiment: lazy load images on scroll
stash@{2}: On feature/auth: wip: oauth token refresh flow
Apply a specific one by index:
git stash apply stash@{2} # brings back the auth work
Inspect before you apply: stash show -p
git stash show gives you a summary of changed files. Add -p for the full diff:
git stash show -p stash@{2}
This is the command most people skip and then regret. Without it you’re blindly restoring changes onto a branch that may have moved significantly since you stashed. A quick show -p takes ten seconds and tells you exactly what you’re about to apply.
If you want to compare the stash diff against the current state of a file side-by-side, paste both into the Text Compare tool — faster than wrangling git diff stash@{N}..HEAD -- path/to/file in your head.
apply vs pop: one difference that actually matters
Both commands restore your stash. One critical difference:
git stash pop= apply + delete the stash entrygit stash apply= apply, keep the stash entry
If you pop and hit a merge conflict, git drops the stash entry before you’ve resolved anything. You now have a conflicted working tree and no stash reference to fall back on.
apply keeps the entry around while you resolve the conflict, then you clean up manually:
# Safer workflow when conflicts are possible
git stash apply stash@{0}
# resolve any conflicts
git stash drop stash@{0} # explicit cleanup once you're happy
The extra drop step is worth it when the stash represents hours of work.
Partial stash with –patch
Sometimes you only want to stash part of your changes. You have a bug fix and half a new feature in the same file, and you want to commit the fix while stashing the feature code.
git stash push --patch (or -p) opens an interactive hunk-by-hunk session:
git stash push -p -m "wip: new feature half"
For each hunk, you get the same y/n/s/q interface as git add -p. Type s to split a hunk into smaller pieces if git’s auto-split isn’t granular enough. It’s slower than a plain stash, but it’s the cleanest way to split a dirty working tree without creating a throwaway branch.
One catch: --patch mode doesn’t include untracked files, so you can’t combine it with -u. If you have new untracked files that are part of the feature you’re stashing, you’ll need to git add them first so they become tracked, then run the partial stash.
Real use cases
Context switching mid-feature. A reviewer leaves urgent feedback on another PR while you’re knee-deep in unfinished code. Stash with a name, switch branches, do the review, come back and pop. No WIP commits, no branch gymnastics.
git stash push -u -m "wip: refactor auth middleware"
git checkout fix/urgent-prod-bug
# ... review and fix ...
git checkout feature/auth-refactor
git stash pop
Verifying a clean test run. You want to confirm your tests pass on a clean working tree — not with your half-finished changes accidentally leaking into the test environment:
git stash push -u
npm test # or pytest, cargo test, whatever
git stash pop
This catches the case where tests pass only because of local modifications. Happens more often than you’d think in repos with shared test fixtures.
Switching branches with a conflicting dirty tree. Git refuses to check out a branch when your working tree has changes that would be overwritten. Stash first, switch, unstash. Faster than git commit --fixup just to move branches.
git stash cheatsheet
| Command | What it does |
|---|---|
git stash push | Stash tracked changes (shorthand: git stash) |
git stash push -u | Include untracked files |
git stash push -m "name" | Stash with a descriptive name |
git stash push -u -m "name" | Untracked + named (the combo you’ll use most) |
git stash push -p | Interactive partial stash (hunk-by-hunk) |
git stash list | List all stashes |
git stash show stash@{N} | Summary of files changed in a stash |
git stash show -p stash@{N} | Full diff of a stash |
git stash apply stash@{N} | Apply a stash, keep the entry |
git stash pop | Apply most recent stash, delete the entry |
git stash drop stash@{N} | Delete a specific stash entry |
git stash clear | Delete all stash entries |
git stash branch <branchname> | Create a new branch from a stash and apply it |
The stash branch escape hatch
One more command worth knowing: git stash branch <branchname>. This creates a new branch at the commit where you stashed, applies the stash, and drops it if the apply is clean. It’s the right move when your stashed changes have grown large enough that they deserve their own branch — and it sidesteps the conflict problem entirely because you’re replaying the stash on the exact tree it came from.
The habit that fixes 90% of stash pain: name everything with -m, and use apply instead of pop until you’re confident the changes integrated cleanly. The extra drop step costs two seconds. Losing a stash you needed costs a lot more.
Install Our Extensions
Add IO tools to your favorite browser for instant access and faster searching
恵 Scoreboard Has Arrived!
Scoreboard is a fun way to keep track of your games, all data is stored in your browser. More features are coming soon!
Must-Try Tools
View All New Arrivals
View AllUpdate: Our latest tool was added on Jun 15, 2026
