Created
August 22, 2023 15:56
-
-
Save demonar/a0a3867b85d2907b3e37f84152bdba5b to your computer and use it in GitHub Desktop.
This script deletes branches that doesn't exist on the remote
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
cd $1 | |
declare -a BRANCHES=(`git for-each-ref --format='%(refname:short)' refs/heads/`) | |
CURRENT=(`git rev-parse --abbrev-ref HEAD`) | |
for BRANCH in "${BRANCHES[@]}" | |
do | |
EXISTS=(`git ls-remote --heads origin refs/heads/"$BRANCH" | wc -l`) | |
if [ "$CURRENT" != "$BRANCH" ] && [ "$EXISTS" = 0 ] | |
then | |
git branch -D "$BRANCH" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment