Skip to content

Instantly share code, notes, and snippets.

@niallsmart
Last active February 8, 2017 20:16
Show Gist options
  • Save niallsmart/047f8281d52c7b8ae9f66e9a7bbe1630 to your computer and use it in GitHub Desktop.
Save niallsmart/047f8281d52c7b8ae9f66e9a7bbe1630 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# generates a script that will delete merged branches
# that were last updated prior to 2016-10-01
#
function list_ancient_branches() {
git branch -r --merged | \
grep -v HEAD | \
xargs -n1 -I {} git show -s --format="%cI %h {}" {} | \
egrep -v '^(2017|2016-1)'
}
list_ancient_branches | while read date sha branch; do
echo "# $date $branch $sha"
echo git push origin --delete ${branch/origin\/}
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment