Skip to content

Instantly share code, notes, and snippets.

@zasadnyy
Created August 25, 2017 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zasadnyy/f38c86ff0c43939ced296f50c76f190c to your computer and use it in GitHub Desktop.
Save zasadnyy/f38c86ff0c43939ced296f50c76f190c to your computer and use it in GitHub Desktop.
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