Skip to content

Instantly share code, notes, and snippets.

@edorian
Created May 7, 2012 08:48
Show Gist options
  • Save edorian/2626744 to your computer and use it in GitHub Desktop.
Save edorian/2626744 to your computer and use it in GitHub Desktop.
Cleanup remote branches not merged with "development" that are stale for 4 weeks. But don't clean master
#!/bin/bash
LOG="tee -a /tmp/branch-cleanup.log"
git checkout development
git fetch
git remote prune origin
branchlist=`git branch -r --merged development | sed 's/ *origin\///' | grep -v 'master$' | grep -v 'development$'`
for branch in $branchlist
do
commitHappendInTheLast4Weeks=`git log -n1 --since="4 weeks ago" "origin/"$branch`
if [ "$commitHappendInTheLast4Weeks" == "" ]
then
echo "To be deleted: "$branch | $LOG
echo `git log -n1 "origin/"$branch` | $LOG
git push origin ":"$branch | $LOG
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment