Skip to content

Instantly share code, notes, and snippets.

@mciuba
Created December 10, 2015 09:11
Show Gist options
  • Save mciuba/44159c1d7621093af9bc to your computer and use it in GitHub Desktop.
Save mciuba/44159c1d7621093af9bc to your computer and use it in GitHub Desktop.
#!/bin/bash
#modified script from: http://stackoverflow.com/a/5396755/2128900
# Git lets you use very readable time formats!
cutoff_time="1 week ago"
# other examples:
# cutoff_time="July 23, 2010"
# cutoff_time="yesterday"
git for-each-ref refs/heads --format='%(refname)' | egrep -v 'master|dev' |
while read branch; do
git reflog expire --expire="$cutoff_time" $branch
if [ "$(git reflog show -1 $branch | wc -l)" -eq 0 ]; then
git branch -D ${branch#refs/heads/}
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment