The reason why you're getting that error is because git stash push
(which git stash -p
is an alias for), doesn't allow custom arguments in order to avoid unintended stashing.
From the documentation for git stash push
:
For quickly making a snapshot, you can omit "push". In this mode, non-option arguments are not allowed to prevent a misspelled subcommand from making an unwanted stash entry. The two exceptions to this are stash -p
which acts as alias for stash push -p
and pathspec elements, which are allowed after a double hyphen --
for disambiguation.
In your case, train.py
is a pathspec, so you must separate it from the recognized options by adding a --
like this:
git stash -p -- train.py
Alternatively, you can spell out the entire command, in which case you don't have to separate the path with a double dash:
git stash push -p train.py
Note that using a double dash --
to clearly separate a pathspec from a command's known options is a convention used by all Git commands that accept paths.