A branch does not have "a stash".
A stash is simply a list of patches, that you can apply wherever you want.
How about appending the warning to a more branch-neutral command like git status then?
You have commit 2414b45 (git 1.6.4, Jun 2009)
Show presence of stashed changes in bash prompt.
Add a '$
' in the __git_ps1
output to show stashed changes are present,
when GIT_PS1_SHOWSTASHSTATE
is set to a nonempty value.
The code for checking if the stash has entries is taken from 'git-stash.sh'.
So try:
export GIT_PS1_SHOWSTASHSTATE=1 # Unix
set GIT_PS1_SHOWSTASHSTATE=1 # Windows
git stash
was initially added to git in commit f2c66ed (git 1.5.3, June 2007) by Nanako Shiraishi.
It is only a very recent git (2.4.2, Apr. 2014, commit ed178ef) which attempted to display a warning, only regarding your current index (irrespective of your current branch):
Cannot apply stash: Your index contains uncommitted changes.
stash
: require a clean index to apply
If you have staged contents in your index and run "stash apply
", we may hit a conflict and put new entries into the index. Recovering to your original state is difficult at that point, because tools like "git reset --keep
" will blow away anything staged. We can make this safer by refusing to apply when there are staged changes.
It's possible we could provide better tooling here, as "git stash apply
" should be writing only conflicts to the index (so we know that any stage-0 entries are potentially precious).
But it is the odd duck; most "mergy" commands will update the index for cleanly merged entries, and it is not worth updating our tooling to support this use case which is unlikely to be of interest (besides which, we would
still need to block a dirty index for "stash apply --index
", since that case would be ambiguous).
This was reverted in commit 1937610 (git 2.4.6, June 2015) though.