Skip to content

Instantly share code, notes, and snippets.

@adelcambre
Created May 31, 2016 20:26
Show Gist options
  • Save adelcambre/2ee36039367763b2e422942a53ed268a to your computer and use it in GitHub Desktop.
Save adelcambre/2ee36039367763b2e422942a53ed268a to your computer and use it in GitHub Desktop.
#!/bin/sh
#/ Usage: clean-merged-branches
#/ Delete locally merged branches
set -e
# show usage maybe
[ "$1" = "--help" ] && {
grep '^#/' <"$0"| cut -c4-
exit 0
}
# fetch and prune remote branches
git fetch origin --prune
# Delete merged local branches
git branch --merged | grep -v '*' | grep -v master | xargs git br -d
# grab list of merged branches
branches=$(
git branch -r --merged |
sed 's@origin/@@'
)
# bail out with no branches
[ -z "$branches" ] && {
echo "no merged branches detected" 1>&2
exit 0
}
# delete the branches or just show what would be done without -f
echo "Merged branches on origin: " 1>&2
echo "$branches"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment