AZ.dev

Stash work in progress including new, untracked files

| git: 2.0+

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

stash untracked wip branches

This entry is one card on a printable cheat sheet:

git Essentials Cheat Sheet

Was this helpful?

Related Entries

List all git-ignored files and folders in a repoFind the commit that broke something with git bisectUndo the last commit but keep the changes