Last Updated: March 06, 2019
· filipekiss

Show when git branch last activity was


So, here at work we have lots of people working in lots of branches. Sometimes, branches are merged into our master and people forget to remove them from the remote.

So I've made a little script to show me when was the last activity on each branch; Just alias the code below to some functions (or create an executable in your path so you can run it from any repo you have on your machine)

for branch in `git branch -a`; 
if [ $branch != "*" ]; then;
    hasAct=$(git log --abbrev-commit --date=relative -1 $branch); 
    lastActivity=$(echo "$hasAct" | grep Date: | sed 's/Date: //');
    echo "$branch last activity was\033[1;31m$lastActivity\033[0m";
    echo ""

You will get something like the output below:


From there, you can see wich branch hasn't been update in a while and delete if you want.

I have another version wich shows me only the branches that have not been updated for the past 15 days. You could automate the deletion of those branches or send yourself a report via e-mail... Anyway, hope you guys liked the tip :)

1 Response
Add your response


Hey Felipe, thanks for this great article. I took what you made and ran with it a bit, turning it into a Python script that can display what I call the "health" of a git branch. Check out my protip, inspired by this one, at:

over 1 year ago ·