Created
March 20, 2013 13:50
-
-
Save mrcasals/5204780 to your computer and use it in GitHub Desktop.
Revisions
-
mrcasals created this gist
Mar 20, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ git branch -d $( git branch --merged | grep -v '^\*' | grep -v 'master' ) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ #!/bin/sh #/ Usage: clean-merged-branches [-f] #/ Delete merged branches from the origin remote. #/ #/ Options: #/ -f Really delete the branches. Without this branches are shown #/ but nothing is deleted. set -e # show usage maybe [ "$1" = "--help" ] && { grep '^#/' <"$0"| cut -c4- exit 0 } # fetch and prune remote branches git fetch origin --prune # grab list of merged branches branches=$( git branch -a --merged | grep remotes/origin/ | grep -v /master | sed 's@remotes/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 if [ "$1" = -f ]; then git push origin $(echo "$branches" | sed 's/^ */:/') else echo "These branches will be deleted:" 1>&2 echo "$branches" echo "Run \`$0 -f' if you're sure." fi