Skip to content

Instantly share code, notes, and snippets.

@shanerk
Created April 8, 2019 18:16
Show Gist options
  • Save shanerk/95e773887d2daeb249b656ab5db45e50 to your computer and use it in GitHub Desktop.
Save shanerk/95e773887d2daeb249b656ab5db45e50 to your computer and use it in GitHub Desktop.
Git Script to Delete Local Branches Removed from the Remotes
# Creates alias which does the following:
# 1. Changes to master branch
# 2. Performs a fetch
# 3. Attempts to delete branches which have been removed from remote
# 4. Performs a verbose branch list
alias gitclean="git checkout master; git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done; git branch -vv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment