Search code examples
gitgit-stash

A one liner for stashing and simultaneously naming untracked changes and files using git stash


Here is the situation:

I have an untracked file in my repository. I'd like to stash this file using git stash and I'd like to name the stash myself. So I found out about git stash save "message", but it seems that this command doesn't work for untracked files. So I need to first run git stash -u then rename the stash.

Is there any workaround for this issue? if this can be considered an issue. Can I stash the untracked files and simultaneously naming them myself in one command?

I am aware of other possibilities such as first staging using git add then using git stash save "message" and as I mentioned earlier it's also possible to first run git stash -u then rename the stash, but I'm looking for one liner command to stash and name my untracked changes and let's say I don't wanna stage or commit my changes.


Solution

  • This can be done by simply running the following command

    git stash save -u "your message or the name of the stash"
    

    This command is presented on the man page.