Created
May 31, 2016 20:26
-
-
Save adelcambre/2ee36039367763b2e422942a53ed268a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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