How to Stash an Untracked File in Git
The git stash command doesn't stash the untracked and ignored files by default. It is necessary to use additional options that we will explain below.
Stashing untracked files
To stash including the untracked files, it is necessary to run the git stash command with the --include-untracked option (same as -u) as follows:
git stash --include-untracked
Stashing ignored files
To stash the ignored files along with the untracked files, it is necessary to run the git stash command with the --all option:
git stash --all
Stashing Files
The git stash command shelves changes made to the working copy making it possible for you to do another work, then come back and re-apply them. If the --include-untracked option is run, all untracked files are also stashed and cleaned up with git clean making the working directory clean. If --all is used instead, ignored files are stashed and cleaned in addition to the untracked files.
Git Ignored Files
Git accepts files as one of the following: tracked, untracked, and ignored.
Ignored files are those that Git has been told to ignore. If you want these ignored files to be committed, first, they should be derived from the Git repository source. Git ignore files are in a file called .gitignore. They are edited and committed manually, as there is no git ignore command in Git.