You run git stash to switch branches. The edited file goes back to normal, but the file you just created stays where it is and gets swept into git add -A on the next branch. After reading this you can tell what git stash takes and what it leaves, and you can get out of a failed git stash pop without losing your edits.
The examples were run on 2026-11-01 with git 2.54.0 (Apple Git-157) on macOS 27.0.1. A script created fresh repositories in a temporary folder, and the file names and contents are made up. Global config was empty, so a setup with aliases or stash.* settings may behave differently. The documentation used is the git-stash page on git-scm.com, marked 2.56.0. Other git versions were not run; by its release notes, git 2.32 is where git stash show learned to show the untracked part.
git stash does not take a new file
There is an edited app.txt and a new.txt that was never added. After git stash, app.txt was clean but new.txt stayed as ??. A new branch and git add -A then put new.txt into that branch's commit.

The documentation says -u (--include-untracked) is what also saves untracked files and removes them from the working folder. A fourth file, secret.env, listed in .gitignore, was added and the three commands compared. A staged new file, added.txt, was saved even without -u. -a took ignored files as well, so secret.env was gone from the folder until pop. In all three cases the four files had the same status after pop as before. -u has limits too: a folder that is its own git repository (?? nested/) printed Ignoring path nested/ and stayed where it was, and an empty folder was removed and did not come back after pop.
DEV NOTES
What each command takes
Edited app.txt, staged new added.txt, untracked new.txt, ignored secret.env
git stash
- Takes: app.txt, added.txt
- Leaves: new.txt, secret.env
git stash -u
- Takes: app.txt, added.txt, new.txt
- Leaves: secret.env
git stash -a
- Takes: all four files
- Leaves: nothing
- secret.env also leaves the folder until pop
Checked with git status --short --ignored before and after. In all three cases the status after pop matched the start. git 2.54.0, run 2026-11-01.
Two more things confuse people. git stash show leaves untracked files out of its default output, so new.txt saved with -u looks missing, and it appeared once --include-untracked was added. And a staged edit, M , came back from a plain pop as the unstaged M; pop --index brought it back as M .
pop when a file of that name now exists
If someone recreates new.txt after git stash -u, pop fails, but it does not stop cleanly. The existing new.txt was not overwritten and the entry stayed on the list, yet the app.txt edit had already been applied. In a copy of the repository, moving the file aside and running pop again produced a different error, that app.txt would be overwritten, and the entry stayed. In that copy new.txt was restored from the entry, so nothing was lost, but the message alone does not make the state clear. In the original repository the script did not pop again and did this instead.
git diff 'stash@{0}'
git stash show --only-untracked --name-only
git show 'stash@{0}^3:new.txt' > new.txt.from-stash
git stash drop
Empty output from the first line means the tracked files in the folder equal the entry. Any other edits appear here too, so read them. The second line lists the new files in the entry. In a repository with three new files, the two whose names were free were restored and only the clashing new.txt kept the later contents. For each clashing file, pull the entry's contents out under a new name as on the third line, which leaves the existing file alone. > overwrites a file of that name, so choose one that does not exist. Drop only after all of that. new.txt.from-stash is untracked too, so the next git add -A would commit it; move or delete it when you are done. That new files sit in a third parent (^3) was observed on git 2.54.0; the documentation used does not describe it. The single quotes stop the shell from reading {0} or ^ in its own way.

On a conflict: resolve, or back out with --merge
If app.txt changes in a commit after the entry was made, pop conflicts. As the documentation says, a conflict keeps the entry on the list. To go forward, fix app.txt, run git add app.txt, check the other files too, and run git stash drop yourself. In the script git restore --staged then unstaged the files without changing their contents.
To back out, be careful with git reset --hard. In two repositories built by the same function, an unstaged edit to other.txt made before the pop disappeared without a warning under --hard and stayed under --merge. The entry stayed on the list in both.

--merge does not protect everything. An other.txt edit staged with git add before the pop disappeared without a warning, as it does under --hard; the table in the git-reset documentation shows the same. If you staged anything before the pop, copy those files first. A hand edit in progress in the conflicted file (half resolved) vanished without a warning and the file went back to HEAD, so copy it first. A hand edit to third.txt, which had merged cleanly, stopped the reset with Cannot merge and the file was untouched. The new.txt restored by pop remained after --merge.
After backing out, you can unpack the entry again on the commit where it was made with git stash branch. Clear the way before the first attempt, because a failed attempt does not stop cleanly either. In one repository, with new.txt still there, it failed with already exists and kept the entry, but it had already switched to the new rescue branch and applied the tracked edits. Moving the file and retrying there failed too: the same name gave already exists for the branch, and another name gave a would be overwritten error. If that has happened, do not retry; on that branch the steps from the earlier section worked: compare with git diff, pull the file out under a new name, then drop. In a separate repository built the same way, comparing the file with the entry and moving it aside first, as below, worked with no conflict: app.txt, third.txt and new.txt had the entry's contents and the other.txt edit came along. Move every file listed by git stash show --only-untracked --name-only; with three new files and only new.txt moved, it failed on the other two, and with all three moved it succeeded. This command removes the entry when it succeeds. The moved new.txt.popped stays as an untracked file too, so clear it the same way.
git show 'stash@{0}^3:new.txt' | diff - new.txt
mv new.txt new.txt.popped
git stash branch rescue
The four paths that were run, and what each one lost, are collected below.
DEV NOTES
When pop keeps the entry
Four paths that were run, and what each one lost
Resolve and go on
- Fix the file, then git add
- Check the other files, then git stash drop
- Lost: nothing, beyond what you chose in the conflict
Back out with git reset --merge
- An unstaged other.txt edit stayed
- Lost: a hand edit in the conflicted file, and edits staged before the pop
- Copy those first
Unpack again with git stash branch
- Move the entry's new files aside first
- It unpacked with no conflict on the original commit
- The entry is removed on success
git reset --hard
- The other.txt edit was gone with no warning
- It was not in the entry, so the entry cannot bring it back
git 2.54.0, macOS 27.0.1, run 2026-11-01. A small example in temporary repositories; other states may behave differently.
If you already dropped it
git stash drop prints the commit id, as in Dropped refs/stash@{0} (ed0ac4b…). The documentation says the normal safety mechanisms cannot recover it and offers a command to look through unreachable commits. In the script the first line below found that commit, the second put it back on the list, and show --include-untracked listed both files.
git fsck --unreachable | grep commit | cut -d' ' -f3 | xargs git log --merges --no-walk --grep=WIP --format='%H %s'
git stash store -m recovered ed0ac4b8cd67f2406d5f140909606a26ecbb71e9
The id differs per repository, so use your own output. An entry made with -m has no WIP in its message, so remove --grep=WIP if the output is empty. There is a time limit too. By the git gc documentation, unreachable objects may be pruned once they are older than two weeks by default, and gc also runs on its own. The age is the object's modification time, not the time since the drop, so an entry made long ago has less time: in a temporary repository with the object files backdated a month, a plain git gc right after the drop removed the commit, while the same steps without backdating kept it. After a deliberate git gc --prune=now in the temporary repository, recovery failed with is not a stash-like commit. Do not run that command in a real repository.
The one thing to remember: look at git status --short before git stash, and if you see ??, add -u. If pop says it kept the entry, read the state before you run it again or reach for --hard. That order is a judgement drawn from the runs above and the documentation. For important work, copy the folder before you try.
Add your perspective.
Share a question, another approach, or something you have tried.
Checking sign-in…
Loading comments…