by war1025 · 6y ago · 0 comments
Slightly different from what you are referring to, but I have the following aliases that are super useful for cleaning up dead branches locally. They make running `git branch` actually return a reasonable list of branches rather than every branch I ever checked out in the past eight years.
listdead = "!sh -c \"git branch -vv | grep ': gone]' | awk '{print \\$1}'\""
prunedead = "!sh -c \"git branch -vv | grep ': gone]' | awk '{print \\$1}' | xargs git branch -D\""
So I will run `git listdead` after I merge something and pull the latest `master`. Then it will usually show the branches that I have merged recently.Then I run `git prunedead` and it goes through and actually deletes them.
I've never run into a case where branches I didn't want removed were in the dead list, but I usually run `listdead` first just in case.
I think I swiped these from a StackOverflow answer at some point. Don't remember.
refage = ! git for-each-ref --format='%(committerdate:relative),%(authorname),%(refname)' --sort -committerdate | column -t -s ','
This will list all refs (including tags, so you might want to grep the output), their relative ages, and who the last commit author was, and then formats it nicely. This makes it easy to see how many branches there and how old they are, as well as who to contact to request deletion.