Resolve a git stash pop conflict (and undo one)
git stash pop hit a conflict — how do I resolve it, and can I undo it?
If you’re seeing this error
CONFLICT (content): Merge conflict in <file>The stash entry is kept in case you need it again.error: could not restore untracked files from stashYou’re in the right place — the fix is below.
Short answer
Good news first: a conflicted pop never drops the stash, so your work is still safe in the stash list. Either resolve the markers and then git stash drop manually, or back out entirely with git checkout . followed by a fresh git stash apply once the tree is clean.
git stash list # confirm the entry is still there
# resolve the markers, then:
git add .
git stash drop
Resolve, stage, then drop — pop leaves the stash behind after a conflict
Does this match your situation?
- 'CONFLICT (content): Merge conflict in <file>' immediately after git stash pop.
- git stash list still shows the entry you thought you popped.
- You want the working tree back the way it was before you popped.
- 'error: could not restore untracked files from stash'
Step-by-step fix
Check the stash is still there — it is
pop is apply followed by drop, and the drop only runs on a clean apply. A conflict stops it, so the entry survives. This single fact is what makes everything below safe to try.
step 1git stash list git stash show -p stash@{0} | head -40Path A: resolve the conflict and keep going
Mechanically this is an ordinary merge conflict — the markers mean what they always mean. Your side is what is currently in the working tree; theirs is what was stashed.
step 2git status # edit each conflicted file, delete <<<<<<< ======= >>>>>>> git add . git stash drop # you must do this yourself after a conflictForgetting the drop is how duplicate stash entries pile up. Nothing else removes it.
Path B: undo the pop entirely
git checkout . discards the half-merged mess and returns to the tree as it was before the pop, with the stash untouched. This is the right choice when you popped onto the wrong branch or the wrong commit.
step 3git checkout . # or, to clear the conflicted merge state as well: git reset --merge git stash list # your entry is still thereThis discards uncommitted changes that were in the tree before the pop as well. Check git stash list first if you are unsure.
Retry cleanly with apply instead of pop
apply never removes the stash, so a second conflict costs you nothing. Use it whenever a pop is likely to be awkward, and drop the entry by hand once you are satisfied.
step 4git switch correct-branch git stash apply stash@{0} # happy with the result? git stash drop stash@{0}Or land the stash on its own branch
stash branch creates a branch from the commit the stash was made on and applies it there, which means the conflict usually disappears entirely — the tree matches what the stash expected.
step 5git stash branch recovered-work stash@{0}On success this drops the stash automatically, because it applied cleanly.
Untracked files that would not restore
Files stashed with -u are not restored if a file of the same name already exists. Move the collision aside and apply again.
step 6git stash show --include-untracked stash@{0} mv newfile.txt newfile.txt.bak git stash apply stash@{0}
Why this works
A stash is not a patch file — it is a real commit (two or three, in fact: one for the index, one for the working tree, and one more for untracked files) parked on a ref no branch points at. Applying it is therefore a genuine three-way merge between what you stashed and where you are now, which is exactly why it can conflict. It also explains the safety property people rely on without knowing why: pop is defined as apply-then-drop, and Git will not run the drop unless the apply succeeded cleanly. The commits are still in the object database, still referenced by refs/stash, and still recoverable — even if you later drop the entry, since git fsck can find those commits until garbage collection runs.
If that didn’t work
- git stash show -p stash@{0} > /tmp/stash.patch gives you the changes as a file to apply by hand.
- git checkout --theirs <file> during the conflict takes the stashed version of that file wholesale.
- If you already dropped the stash, git fsck --unreachable finds the commit and git stash apply <hash> restores it.
- Enable rerere so a stash you keep re-applying resolves itself the same way every time.
How to stop it happening again
- Prefer apply over pop when you are unsure — dropping later is one command.
- Stash with a message: git stash push -m "wip: login form" makes the list readable.
- Pop onto the branch you stashed from; most conflicts come from popping somewhere else.
- For anything longer than a coffee break, commit on a scratch branch rather than stashing.
Commands used in this guide
git stashPark uncommitted work temporarily so you can do something else.
git checkoutThe old all-in-one: switch branches, restore files, or detach HEAD.
git resetMove the current branch pointer, optionally rewriting the index and your files.
git switchMove to another branch - the modern, safer half of git checkout.
git rerereRemember how you resolved a conflict and replay it automatically next time.
Still stuck?
Search the full command reference and every other rescue guide — there are 76 of them, covering everything from detached HEAD to force-push disasters.
Browse all guides →Frequently asked questions
Does git stash pop delete my stash if there is a conflict?
No. pop is apply followed by drop, and the drop only runs when the apply is clean. After a conflict the entry is still in git stash list — which means you can always back out and try again.
How do I undo a git stash pop that caused a conflict?
git checkout . discards the conflicted state and restores the tree as it was before the pop, or git reset --merge clears the merge state as well. The stash entry is untouched, so you can re-apply it whenever you are ready.
Why does my stash still appear after popping it?
Because the pop conflicted, so Git deliberately kept it. Once you have resolved and staged the files, remove it yourself with git stash drop — nothing else will.
What is the difference between git stash pop and git stash apply?
pop applies the stash and deletes it; apply applies it and keeps it. apply is the safer default when a conflict is likely, because a failed attempt costs you nothing and you can drop the entry by hand afterwards.
Can I apply a stash to a different branch?
Yes, and it is a common cause of conflicts, because the stash was recorded against a different tree. git stash branch <name> avoids that: it creates a branch at the commit the stash was made on and applies it there, where it usually goes in cleanly.
Related rescue guides
I ran git stash drop (or git stash clear) — can I get the stash back?
Stashes are stored as real commit objects, so dropping one only removes it from the stash list — the commit itself survives as an unreachable object. git fsck --unreachable finds it, and git stash apply <hash> puts the work back.
Read the fix →Always fixableGit says I have merge conflicts — how do I fix them?
Git pauses and marks the clashing sections with <<<<<<<, ======= and >>>>>>>. Edit each file to the version you actually want, delete the markers, git add the file, then git merge --continue. If it gets overwhelming, git merge --abort returns you to exactly where you started.
Read the fix →Always fixableGit won't let me pull because of local changes — how do I fix it?
Git is refusing to overwrite uncommitted edits to files the incoming commits also change. Commit them, stash them, or discard them — stashing is the reversible choice and takes one command.
Read the fix →Always fixableHow do I work on two branches at the same time without stashing or re-cloning?
git worktree add ../hotfix main gives you a second folder checked out to a different branch, sharing the same .git object store. No stashing, no second clone, no waiting for your build to reinstall. When you're done, git worktree remove ../hotfix cleans it up.
Read the fix →