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?
The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git. Status output does not show you any information regarding the committed project history.
Git Stash List. The Git stash list command will pull up a list of your repository's stashes. Git will display all of your stashes and a corresponding stash index. Now, if you wish to view the contents of a specific stash, you can run the Git stash show command followed by stash@ and the desired index.
To better identify a git stash, add a custom name or message by using the option -m followed by the message when creating a stash. We can quickly verify the message was added to the stash by listing the git stashes using the git stash list command.
Stage all your files that you need to stash. Run git stash --keep-index . This command will create a stash with ALL of your changes (staged and unstaged), but will leave the staged changes in your working directory (still in state staged). Now your "good stash" has ONLY staged files.
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
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.
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$)$
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With