git stash alone leaves new files behind. Add -u so the stash carries them too, and a message so you can find it later.
git stash push -u -m "wip: login form"
Bring it back with the stash still saved, then drop it once you’re sure:
git stash apply
git stash drop
git stash pop does both in one step, but if applying conflicts, the stash is kept and you have to drop it yourself after resolving.
Why plain stash loses files
A stash records tracked changes: the index and the working tree of files git already knows. A file you created and never git added is untracked, so it isn’t in the stash and stays in the working tree. That’s fine until you switch branches and the new file collides, or you delete it thinking it was stashed.
Gotchas
-ustill skips ignored files.-aincludes those too, which you almost never want; it will stashnode_modulesif it’s ignored.- Stash one part of the change with
git stash push -m "msg" -- path/to/file, or interactively with-p. - Stashes aren’t branch-specific.
git stash listshows all of them, and a stash made onmainapplies on any branch. - A stash that has sat for a week is usually easier to recover as a branch:
git stash branch wip-login stash@{0}checks out the commit the stash was made on, applies it, and drops it.