Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Delete all git branches that are gone from origin
#!/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
You can’t perform that action at this time.