Git stash a single file: park the file, not the tree
Git stash a single file with git stash push -m "why" -- PATH: the named file parks in stash@{0}, every other dirty file never moves. Pathspec since git 2.13 (May 2017).
Git stash a single file with git stash push -m "why" -- <path>: the named file parks in stash@{0} and every other dirty file never moves. Plain git stash sweeps the whole tree — wrong shape when one file is ready to hand over and the rest are genuinely unfinished.
The stash is a scratchpad, not a branch.
git stash a single file: the before and after
BEFORE · git status --shortM app.conf ← must moveM notes.mdM main.pygit stash push -m "app.conf prod tweak" -- app.confAFTERM notes.md ← never movedM main.py ← never movedstash@{0}: On main: app.conf prod tweak
app.conf is back at its committed state and sits in stash@{0}. The -m line earns its three seconds the moment git stash list has more than one entry — names like "WIP" age badly.
Where does the pathspec go?
After --. Everything past the double dash is a path, not a flag — the same convention as git checkout -- <path>. It is not decorative: older git could misread a bare path. A brand-new file has no tracked history, so plain push skips it; -u includes it, -a sweeps ignored files too.
git stash push -- <path> | git stash -p | |
|---|---|---|
| Granularity | Whole files | Individual hunks |
| Speed | One command, scriptable | Interactive, per-hunk |
| Repeatable in CI | Yes — paths as arguments | No — needs a human at the prompt |
| Best for | "this file, not the rest" | "this change, not that one" |
| Since | git 2.13 (May 2017) | Long-available |
git stash -p walks each hunk and asks Stash this hunk [y,n,q,a,d,j,g,/,e,p,?]?. Answer y for hunks that belong in the stash, n for those that stay — the same machinery as git add -p.
-p when the boundary is inside it.One file back out
git stash apply stash@{0}— apply without dropping, safe to re-rungit restore --source stash@{0} -- app.conf— one file out, the entry staysgit stash pop— the normal path, but all-or-nothing; a conflict aborts it with the entry preserved
pre-2.23 spelling, and when the stash is wrong
git checkout stash@{0} -- app.conf Stashes live only on your machine, carry no message beyond one line, and are famously easy to forget — git stash list archaeology is a genre. Work that must survive days, travel between machines, or carry a real commit message belongs on a branch: git switch -c wip-labels, commit, switch back. The stash is for the next few hours, not the next sprint.
- git 2.13+ pathspec · git 2.23+ restore · all majors · first published 2026-09-21
- pathspec form, -u flag, hunk prompt and restore-from-stash spelling are documented git stash behaviour
- the before/after status output above is exactly what the sequence prints