Created
August 25, 2017 10:48
-
-
Save zasadnyy/f38c86ff0c43939ced296f50c76f190c to your computer and use it in GitHub Desktop.
Delete all git branches that are gone from origin
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 | |
#git fetch --prune # run fetch --prune to update local refs that were removed on orign | |
BRANCHES=$(git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}') | |
echo Branches that are gone on origin: | |
echo $BRANCHES | tr " " "\n" | |
read -p "Delete these branches (y/n)? " answer | |
if [ "$answer" = "n" ]; then echo aborting && exit; fi | |
echo $BRANCHES | xargs -n 1 git branch -D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment