Skip to content

Instantly share code, notes, and snippets.

@rdok
Created March 12, 2016 16:11
Show Gist options
  • Save rdok/06e01e1ee49a25fe7fc4 to your computer and use it in GitHub Desktop.
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.
#!/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