Created
March 12, 2016 16:11
-
-
Save rdok/06e01e1ee49a25fe7fc4 to your computer and use it in GitHub Desktop.
Delete all remote remote git branches, except 'master', and 'stage'. Run usinb bash instead of sh.
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 characters
#!/bin/bash | |
declare -a skip_branches=("master" "stage") | |
# Credits due http://stackoverflow.com/a/10312587/2790481 | |
for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done | |
branches=$(git branch) | |
function branch_should_not_be_skipped { | |
branch=$1; | |
for current_branch in $skip_branches; do | |
if [ "$branch" == "$current_branch" ]; then | |
return 1; | |
fi | |
done | |
return 0; | |
} | |
for branch in $branches; do | |
if branch_should_not_be_skipped $branch; then | |
git push origin --delete $branch | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment