Skip to content

Instantly share code, notes, and snippets.

@asabla
Created April 23, 2021 18:29
Show Gist options
  • Save asabla/2df3ac1b2dff834be9781341edf48433 to your computer and use it in GitHub Desktop.
Save asabla/2df3ac1b2dff834be9781341edf48433 to your computer and use it in GitHub Desktop.
Prune old git branches
func_gitprune() {
echo 'Starting git prune'
echo "Found $(git branch | wc -l) number of local branches"
echo "Starts prune of origin branches...."
git remote prune origin
echo "Local branches which can be removed:"
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}'
echo "Pruning local branches..."
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -d
echo "$(git branch | wc -l) number of local branches after gitprune"
echo "Done!"
}
# clear no longer tracked git branches (prune)
alias gitprune="func_gitprune"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment