Stash just a single file

Question

I'd like to be able to stash just the changes from a single file:

git stash save -- just_my_file.txt

The above doesn't work though. Any alternatives?

Answer

If you do not want to specify a message with your stashed changes, pass the filename after a double-dash.

$ git stash -- filename.ext

If it's an untracked/new file, you will have to stage it first.

However, if you do want to specify a message, use push.

git stash push -m "describe changes to filename.ext" filename.ext

Both methods work in git versions 2.13+

How do I create a remote Git branch?

How do you attach a new pull request to an existing issue on github?