Skip to content

Instantly share code, notes, and snippets.

@thomasaarholt
Created October 29, 2024 11:23
Show Gist options
  • Save thomasaarholt/0ce51467ec9dbc7ac1f57353ed5a76cf to your computer and use it in GitHub Desktop.
Save thomasaarholt/0ce51467ec9dbc7ac1f57353ed5a76cf to your computer and use it in GitHub Desktop.
The following code will print if you have any stashed code on a given branch. Add it to a repo's git/hooks/post-checkout to print whenever you change branch
# print stashes that exist for the currently switched-to branch
GREEN='\033[0;32m'
NC='\033[0m' # No Color
branch=$(git rev-parse --abbrev-ref HEAD)
stashes=`git stash list | grep "WIP on $branch"`
if [ "$stashes" ]
then
echo "${GREEN}You have the following stashes for this branch:"
echo "${stashes}${NC}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment