Git stash: save your changes without committing, then get them back
By Pull This RepoPosted 4 min read
Short answer
Git stash saves your uncommitted changes and gives you a clean working folder, so you can switch branches or pull without committing half-done work. Run git stash to save, git stash list to see what is saved, and git stash pop to bring the latest one back. Add -u to include untracked files. git stash apply restores a stash but keeps it in the list.
Git stash puts your uncommitted changes on a shelf and resets your files to the last commit, so you can switch branches, pull, or fix something urgent without making a messy commit. When you are ready, you take the changes back off the shelf. This page covers the commands you will use: saving with and without untracked files, git stash list, git stash pop versus git stash apply, dropping old stashes, stashing one file, and getting back a stash you deleted by accident. Every flag was checked against the git stash manual on git-scm.com on 22 November 2026.
What does git stash do?
It saves the current state of your working folder and staging area, then makes the folder match your last commit. The git stash docs say running git stash with no arguments "is equivalent to git stash push". A quick example:
git stash # save changes, clean the folder
git switch main # do something else
git switch - # come back
git stash pop # restore the changesEach stash gets a default label like "WIP on main", plus the commit it was based on. Name it yourself with -m, which makes a long list much easier to read:
git stash push -m "half-done login form"How do you stash untracked files?
Add -u. By default, git stash only saves changes to files Git already tracks, so a brand new file stays in your folder.
| Command | Tracked changes | Staged changes | Untracked files | Ignored files |
|---|---|---|---|---|
git stash | yes | yes | no | no |
git stash -u | yes | yes | yes | no |
git stash -a | yes | yes | yes | yes |
-u is short for --include-untracked and -a for --all. The docs say both stash those files "and then cleaned up with git clean", so they disappear from your folder until you restore the stash. Use -a with care: it also sweeps up ignored folders such as node_modules or build output.
How do you see your stashes with git stash list?
Run git stash list. Each entry shows its name, the branch you were on, and the commit it was based on:
stash@{0}: On main: half-done login form
stash@{1}: WIP on feature: 6ebd0e2 Add headerstash@{0} is always the newest. To see what is inside one:
git stash show # summary of changed files, newest stash
git stash show -p stash@{1} # full diff of the second stash
git stash show -u # include untracked files in the viewThe docs note you can refer to a stash by its number alone, so git stash show -p 1 means the same as stash@{1}.
What is the difference between git stash pop and git stash apply?
git stash pop restores the changes and deletes the stash. git stash apply restores them and keeps the stash in the list.
git stash pop # newest stash, then remove it
git stash apply # newest stash, keep it
git stash apply stash@{2} # a specific stash, keep itUse apply when you want the same changes on more than one branch, or when you are not sure the restore will go cleanly. If either one hits a merge conflict, the git stash docs say the stash "is not removed from the stash list". Fix the conflicts, then run git stash drop yourself.
Without --index, Git restores your working folder but does not try to rebuild what you had staged. Add --index to pop or apply to restore the staging area too, which the docs say can fail when there are conflicts.
How do you delete stashes?
git stash drop removes one stash, newest by default. git stash clear removes all of them.
git stash drop # remove stash@{0}
git stash drop stash@{3} # remove a specific one
git stash clear # remove every stashThe docs warn that cleared entries are "subject to pruning, and may be impossible to recover", so check git stash list before you clear.
How do you stash a single file?
Use git stash push with a path. Only matching files are stashed; everything else stays in your folder:
git stash push src/app.js
git stash push -m "just the styles" src/styles.css src/theme.cssWith the word push you can list paths directly. If you leave push out, the docs say paths are only allowed after a double dash, --, to stop a typo from being read as a file name.
Three related options help when you want to keep some work out of the stash:
git stash push --staged(or-S) stashes only what is staged, leaving the rest.git stash push --keep-index(or-k) stashes everything but leaves staged changes in place, useful for testing part of your work before you commit it.git stash push -plets you pick hunks one by one.
How do you turn a stash into a branch?
Run git stash branch with a new branch name:
git stash branch login-form stash@{0}The docs say this creates a branch from the commit where the stash was made, applies the stash there, and drops it if that works. It is the fix when git stash pop keeps conflicting because your branch has moved on too far.
How do you recover a dropped stash?
If you dropped or cleared a stash by mistake, it may still exist as an unreachable commit until Git cleans up. The git stash docs give this command to list candidates:
git fsck --unreachable |
grep commit | cut -d\ -f3 |
xargs git log --merges --no-walk --grep=WIPThe --grep=WIP part matches default stash names; change it to match a message you set with -m, or remove it to see every candidate. When you find the right commit, apply it by its ID:
git stash apply 1a2b3c4git stash apply accepts any commit that "looks like a commit created by stash push", according to the docs.
What is the catch?
Stashes are local and easy to forget. git push does not send them anywhere, so they never reach GitHub, and a long git stash list of "WIP on main" entries is hard to sort out weeks later. Name your stashes, pop them soon, and turn anything long-lived into a branch or a commit. If you only meant to take a file out of the staging area, how to unstage a file in Git is the lighter fix, and the Git cheat sheet lists stash alongside the other undo commands.
Pull it. Stash it.
Questions people ask
What is the difference between git stash pop and git stash apply?
Both put stashed changes back into your working folder. git stash pop then removes that stash from the list, while git stash apply leaves it there so you can apply it again, for example on another branch. If pop hits a conflict, the git stash docs say the stash is kept and you drop it yourself after fixing it.
Does git stash include untracked files?
Not by default. Plain git stash saves changes to tracked files and staged changes only, so new files stay in your folder. Add -u or --include-untracked to stash untracked files too, or -a or --all to also stash files your .gitignore ignores.
How do I stash only one file?
Run git stash push followed by the file path, for example git stash push src/app.js. The git stash docs say only files matching the path are stashed and rolled back, and everything else stays as it is. Add -m with a message so you can find it later in git stash list.
Can I get back a stash I dropped by mistake?
Often, yes, if Git has not cleaned it up yet. The git stash docs give a git fsck command that lists stash commits that are no longer reachable. Find the one you want by its message, then run git stash apply with that commit ID to bring the changes back.
Where are stashes stored, and do they get pushed?
Stashes live in your local repo, under refs/stash and its reflog. git push does not send them, so they never reach GitHub and are lost if you delete the folder. The current git stash docs also list export and import subcommands for moving stashes between repos with normal fetch and push.
Sources
More repos like this
Get tomorrow's repo in your feed
One free, open source repo a day as a short video, shown working, with the catch named. Pull it. Stash it.
