Skip to content

Instantly share code, notes, and snippets.

@ross-urban
Created January 31, 2018 23:00
Show Gist options
  • Save ross-urban/81ffe3bc783801572445632a49a4bdad to your computer and use it in GitHub Desktop.
Save ross-urban/81ffe3bc783801572445632a49a4bdad to your computer and use it in GitHub Desktop.
Delete local git branches with deleted remotes
function orphaned-branches {
git branch -vv | cut -c 3- | awk '$4 ~/gone\]/ { print $1 }'
}
function gitclean {
git remote -v prune origin
echo "WARNING: The following branches will be deleted!"
RESPONSE=$(orphaned-branches)
echo "$RESPONSE"
echo
echo "Are you sure (yN)?"
read yn
if [[ $yn =~ ^[yY]$ ]]
then
echo "$RESPONSE" | xargs git branch -D
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment