Print related stored stashes when checkouting a branch
I use git stashes parsimoniously and generally prefer to do a WIP commit when I must leave a branch. Yet, sometimes, when I struggle to find a good implementation, I cannot resolve myself to commit the code -even as a WIP- and prefer to stash it away.
So git stashes are places where I put my half-baked attempts for an hypothetic later use.
As soon as I checkout a branch, I call git log
to get back into the swing, if the top commit is labelled as WIP, I soft reset it and am right back to work. Checking available stashes on checkout is not as natural for me and I forget to do it half the time thus losing the code stashed or wasting my time rewriting it …
I figured today that I could use the fact that default stashes messages are of the form “WIP on <branchname>
:” to grep them just after performing a checkout. That gave birth to my .gitconfig
co
alias :
1co = "!f() { git checkout \"$@\" && git stash list | grep \"$1:\"; }; f"
… and gives following display :
Tadaam! No more excuses to let stashes rot.