How do you stash an untracked file? How do you stash an untracked file? git git

How do you stash an untracked file?


To stash your working directory including untracked files (especially those that are in the .gitignore) then you probably want to use this cmd:

git stash --include-untracked

Alternatively, you can use the shorthand -u instead of --include-untracked, or simply git stash --all which stashes all files, including untracked and ignored files. This bahaviour 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.


As of git 1.7.7, git stash accepts the --include-untracked option (or short-hand -u). To include untracked files in your stash, use either of the following commands:

git stash --include-untracked# orgit stash -u

Warning, doing this will permanently delete your files if you have any directory/ entries in your gitignore file.*


Add the file to the index:

git add path/to/untracked-filegit stash

The entire contents of the index, plus any unstaged changes to existing files, will all make it into the stash.