Last active
February 23, 2017 05:50
-
-
Save meriadec/9e91a8fdba5cc14f53dbd66be66c427e 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/bash | |
# | |
# Usage: | |
# ./remove-merged <branch> | |
# | |
# if no branch given, use the current branch | |
# | |
targetBranch=$1 | |
# if no target branch given, assume it is the current branch | |
if [ "$targetBranch" == "" ]; then | |
targetBranch=$(git branch | grep \* | sed -E 's/\* (.*)$/\1/g') | |
fi | |
# get branches that needs to be deleted | |
branchesToDelete=$(git branch -r --merged $targetBranch \ | |
| grep -v $targetBranch \ | |
| grep -v '/HEAD') | |
for b in $branchesToDelete; do | |
remote=$(echo $b | sed -E 's/([^/]*).*/\1/g') | |
bName=$(echo $b | sed -E 's/[^/]*\/(.*)/\1/g') | |
# echo command instead of executing it :D | |
# execute at your risks :D | |
# | |
# git push $remote :$bName | |
echo "git push $remote :$bName" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment