The fact is that untracked files are not taken into account when making some git
commands. This is safer because ignoring them is the safest choice that we can make by default (an automatic add would be really not something you want, believe me).
So, if you want to include the newly added files into your stash, just git add
them and track them.
EDIT
Sorry, I got confused between newly added files and tracked new files.
According to the manpage of git stash
:
If the --keep-index
option is used, all changes already added to the index are left intact.
If the --include-untracked
option is used, all untracked files are also stashed and then cleaned up with git clean, leaving the working directory in a very clean state. If the --all option is used instead then the ignored files are stashed and cleaned in addition to the untracked files.
With --patch
, you can interactively select hunks from the diff between HEAD
and the working tree to be stashed. The stash entry is constructed such that its index state is the same as the index state of your repository, and its worktree contains only the changes you selected interactively. The selected changes are then rolled back from your worktree. See the “Interactive Mode” section of git-add(1)
to learn how to operate the --patch
mode.
The --patch
option implies --keep-index
. You can use --no-keep-index
to override this.
Then, later on, you are given an example:
Testing partial commits
You can use git stash save --keep-index
when you want to make two or more commits out of the changes in the work tree, and you want to test each change before committing:
# ... hack hack hack ...
$ git add --patch foo # add just first part to the index
$ git stash save --keep-index # save all other changes to the stash
$ edit/build/test first part
$ git commit -m 'First part' # commit fully tested change
$ git stash pop # prepare to work on all other changes
# ... repeat above five steps until one commit remains ...
$ edit/build/test remaining parts
$ git commit foo -m 'Remaining parts'
So, in order to include all the changes you have inside the current branch to be present in the stash, you should either use the --keep-index
option, or select carefully what file you want to include by marking them with --patch
option when adding it.