Git Stash: push, pop, apply, and Partial Stashing
A stash is a commit with two or three parents, and it leaves untracked files behind by default. When a temporary branch or a worktree is the better tool.

Quick Summary
A stash is a commit — two or three of them, in fact, stored under refs/stash with the working tree and index captured as separate parents. git stash push cleans the working tree and records it; pop applies it and drops it; apply applies it and keeps it in the list.
The default stash covers tracked files only. Untracked files need -u, ignored files need -a, and forgetting that is how new files get "lost" in a conflict — they were never in the stash.
Stashes are a stack, addressed by index (stash@{0} is newest), and they apply to whatever branch is checked out, not the branch they were created on. For work that will live longer than an hour, a temporary branch is safer: a stash has no reflog of its own beyond the shared one, and a mistaken drop or clear needs git fsck to recover.
A stash is also not a backup. It lives in the same repository as the work, in objects that ordinary git gc may prune once the entry is dropped, and it is never pushed by git push. Anything that must survive a laptop failing belongs in a commit on a remote branch, even if the branch is named wip/scratch and deleted next week.
Basic Syntax and Core Signatures
git stash push # tracked changes
git stash push -m "wip: login form" # with a message, always do this
git stash push -u # include untracked files
git stash push -a # include ignored files too (rarely)
git stash push -k # keep the index staged, stash the rest
git stash push --staged # stash only what is staged (2.35+)
git stash push -p # hunk by hunk
git stash push -- src/parser.ts # only these paths
git stash list # stash@{0}: On main: wip: login form
git stash show # diffstat of the newest
git stash show -p stash@{1} # full patch
git stash apply # apply, keep in the list
git stash apply --index # restore staged/unstaged split
git stash pop # apply and drop on success
git stash pop stash@{2}
git stash drop stash@{1}
git stash clear # drop everything, no prompt
git stash branch fix-login stash@{0} # new branch from the stash's original basegit stash branch is the underused one: it creates a branch at the commit the stash was made on, applies the stash there, and drops it if the apply is clean. That is the correct response when a stash no longer applies to the current branch.
Key Comparison Table
| Command | Working tree | Stash list | Conflicts possible | Use when |
|---|---|---|---|---|
push | Cleaned | One more entry | No | Park work to switch branches |
pop | Changed | Entry removed on success | Yes | You want the work back now |
apply | Changed | Entry kept | Yes | You may want it on two branches |
branch <name> | Changed on a new branch | Removed on clean apply | Yes | The stash no longer applies |
drop | Untouched | One fewer entry | No | The work is no longer needed |
clear | Untouched | Empty | No | Cleanup, irreversible |
| Flag | Effect | Trap |
|---|---|---|
-u / --include-untracked | Adds new files | Without it, new files are not stashed |
-a / --all | Adds ignored files too | .env and build output land in the stash |
-k / --keep-index | Leaves staged changes in the tree | Test runs see only staged code |
--staged | Stashes only the index | Working tree changes stay |
-- <pathspec> | Scopes to paths | Paths must come after -- |
Practical Edge Cases and Deep Dives
1. The stash that does not include your new files
git stash push then git switch main succeeds, and the two files you just created stay in the working tree because they were untracked — they then follow you to main as untracked files, and if main has tracked files at those paths the switch fails. Use -u and check git status --porcelain after the stash to confirm a clean tree.
2. pop with a conflict keeps the stash
A conflicted pop leaves the stash in the list and the working tree with conflict markers. That is deliberate: the entry is your only copy. Resolve, git add, then git stash drop explicitly. Scripts that assume pop always removes the entry end up with duplicates.
git stash pop # conflict
# resolve files
git add -A
git stash drop # now it is safe3. Applying a stash to a different branch
Stashes are not branch-scoped. git stash apply on another branch replays the diff as it was, so a change that depended on a renamed symbol produces either a conflict or, worse, a clean apply that compiles but is semantically wrong. git stash show -p before applying is cheap insurance.
Preserving the staged split. A plain apply merges everything into the working tree, losing which hunks were staged. --index restores the index too, but fails if the index has diverged. For a partial-stash workflow — stage a subset, stash the rest, commit on another branch — --index is what makes the round trip lossless.
4. Partial stashing by path and by hunk
git stash push -p walks hunks like add -p, and git stash push -- path/ scopes by path; both leave the rest of the tree untouched. Combined with -k, this is the standard way to park an unrelated refactor while committing a hotfix:
git stash push -k -m "refactor: extract parser" -- src/parser.ts
git commit -m "hotfix: null check"
git stash pop5. Stash as a commit, and recovering a dropped one
refs/stash holds a commit whose first parent is HEAD at stash time and whose second parent is the index commit; a third parent exists when untracked files are included. That means git show stash@{0}:path/file reads a file from the stash, and a dropped stash is recoverable with git fsck --unreachable | grep commit followed by git stash apply <sha> — as long as garbage collection has not run.
6. Choosing between stash, branch, and worktree
The three tools overlap, and picking by habit is why people run out of stash entries. A stash is right for minutes-to-hours: a hotfix interrupts a refactor, you need a clean tree for a test run. A wip/ branch is right for days: the work needs review, a colleague needs it, or the machine may be replaced. A worktree is right when both must exist at once — an old release to patch while main keeps moving:
git worktree add ../app-release-2.4 release/2.4
git worktree list
git worktree remove ../app-release-2.4A worktree has its own index and working tree but shares the object database and refs, so the two checkouts cannot hold the same branch at the same time. That is a feature: the branch checkout is unambiguous, and switching no longer requires stashing at all.
refs/stash is also visible to tooling: a stash entry appears in git fsck output, survives git gc as long as its reflog entry exists, and is copied by git clone --mirror but not by a normal clone. That asymmetry explains why a dropped stash is recoverable on the machine where it was created and nowhere else.
Hygiene. A stash is local state that no review process sees, so it accumulates the same way dotfiles do. Two simple rules keep it from becoming a mystery: every stash carries a message (-m) naming the branch and the intent, and nothing survives a week. A short cleanup pass is enough:
git stash list --date=iso | tail -20
git stash show -p stash@{5} | head -40 # decide: branch, reapply, or drop
git stash drop stash@{5}In CI, a stash is almost always a mistake. Build agents get a fresh checkout per job, so a stash there is invisible work that disappears when the container ends. If a pipeline needs to park changes between steps, commit to a throwaway branch with an explicit name — then the step's state is visible in the log, and the next failure is diagnosable.
Common Git Operation Mistakes
| Symptom | Cause | Fix |
|---|---|---|
| New files missing after a stash | push without -u | Re-add them; use -u next time |
.env captured in a stash | -a used | git stash show -p to inspect, drop and redo |
| Stash applies with conflicts every time | Base commit is far behind | git stash branch <name> <stash> |
| Two copies of the same change | apply used instead of pop | git stash drop after verifying |
| Staged/unstaged split lost | apply without --index | Use --index next time, re-stage manually |
| Stash list grown to dozens of entries | Never cleaned up | git stash list, review, drop or convert to branches |
Stash lost after clear | No prompt on clear | git fsck --unreachable, apply the dangling commit |
| Stashed work not in the branch you expected | Stashes are not branch-scoped | Check git stash list messages, apply to the right branch |
Try matching browser tools
All toolsSmall utilities that fit Git work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Git guides
All Git guidesGit config: Aliases, rerere, and Credential Helpers
Five config scopes decide one value at a time. Aliases are user-level shorthand, rerere records conflict resolutions, and credential helpers choose where your secret lives.
Git Hooks: pre-commit, commit-msg, and Husky Automation
Hooks live in .git/hooks, which a clone never receives, so core.hooksPath and Husky are how they travel. Exit codes abort the operation, and every hook is bypassable.
Git bisect: Binary Search, Automated Scripts, and Bug Hunting
Mark one bad and one good commit and Git halves the range each step. bisect run automates it through exit codes, and monotonicity is the assumption that must hold.
Git ignore: Patterns, Negation, and Untracking Cached Files
Patterns are relative and last match wins, but a negation cannot revive a file inside an excluded directory. Ignore rules never touch tracked files: rm --cached first.
More in Git
All Git guidesThe guides filed next to this one in Git, in library order.