How to Stash an Untracked File
Git allows stashing you untracked files and ignored files only running just a single command. However, the methods of stashing have changed from time to time depending on different Git versions. Let’s try to explain what you should do to solve this problem more efficiently.
For stashing your working directory with untracked files including those in .gitignore in newest versions of Git run the git stash command with the --all option which will include untracked and ignored files automatically:
git stash --all
In older versions of Git the following issue was possible to solve with the help of the --include-untracked option:
git stash --
git stash -u
Git version 1.7.7 allows running git stash --include-untracked or git stash save -u to stash untracked files without staging them.
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.