g-1n9w
Last Updated: February 25, 2016
·
3.596K
· filipekiss
1900150 10203074354438338 1015529188 n

Show when git branch last activity was

git

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`; 
do; 
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 ""
fi;
done;

You will get something like the output below:

Picture

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 :)

Say Thanks
Respond

1 Response
Add your response

12949
9a53b15e18647a2fdb6d839c8f0c3c34

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:
https://coderwall.com/p/5xgq7w?i=1&p=1&q=author%3Ajwir3&t[]=jwir3

over 1 year ago ·
Filed Under