I have changes to a file, plus a new file, and would like to use git stash to put them away while I switch to another task. But git stash by itself stashes only the changes to the existing file; the new file remains in my working tree, cluttering up my future work. How do I stash this untracked file?
Share
To stash your working directory including untracked files (especially those that are in the
.gitignore) then you probably want to use this cmd:Alternatively, you can use the shorthand
-uinstead of--include-untracked, or simplygit stash --all(see warning below for this one) which stashes all files, including untracked and ignored files. This behaviour changed in 2018, so make sure your git is up to date.Warning: there seems to be (or have been) situations in which contents of ignored directories could be deleted permanently. See this archived website for more information.