Created
July 16, 2020 19:57
-
-
Save nilandev/2cb74db9b7bb73625507aa7929c8b49a to your computer and use it in GitHub Desktop.
Delete all other local branches except master, develop or release/*
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 | |
# Move to master branch. Delete all other local branches except master, develop, release/* or project/* | |
# Move to master branch | |
git checkout master | |
# Collect branches | |
branches=() | |
eval "$(git for-each-ref --shell --format='branches+=(%(refname))' refs/heads/)" | |
for branch in "${branches[@]}"; do | |
old="refs/heads/" | |
branchName=${branch/$old/} | |
if [[ "$branchName" != "master" && "$branchName" != "develop" && "$branchName" != "release/"* ]]; then | |
git branch -D $branchName | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment