Irfy
Irfy

Reputation: 9607

Can git status be made to mention the stash?

I tend to forget that I had stashed some changes. I'd like to see stash mentioned in git status output, when the stash is not empty. Is there a way to get git status do this?

Upvotes: 10

Views: 648

Answers (2)

gib
gib

Reputation: 2131

This is now a built-in option in git status, so you can just do:

[status]
  showStash = true

If you're not comfortable editing your git config file, you can do

git config --global status.showStash true

Upvotes: 12

Irfy
Irfy

Reputation: 9607

As far as I can see, there is no built-in option to do this, but there are a couple of ways of achieving the desired effect.

git-prompt.sh

Source the git-prompt.sh script as described in its documentation, and set the GIT_PS1_SHOWSTASHSTATE variable, e.g. in ~/.bashrc:

. ~/.bash/git-prompt.sh
GIT_PS1_SHOWSTASHSTATE=1
PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'

Now your command prompt will show a dollar sign next to the branch name in the git prompt:

user@host:~/repo (master$)$

git alias

You can make an alias for the desired functionality, although the alias cannot be status, it must be different from any built-in command:

git config --global alias.vstatus '!git status; git stash list'

This will set up a global alias vstatus (verbose status) that will simply run git status and git stash list back to back.

shell alias

One can always make a shell alias to intercept git subcommand invocation, as git aliases for built-in commands are ignored. In .bash_aliases:

git () {
    command git "$@" || return # preserve $?
    [[ $1 = status ]] && command git stash list
}

This will simply always run git stash list after every git status. When the stash is empty, nothing will be output.

Upvotes: 4

Related Questions