Skip to content

Instantly share code, notes, and snippets.

@alexanderbez
Created September 10, 2018 21:20
Show Gist options
  • Save alexanderbez/ea35747b626f1aa646803bf4a5f056bb to your computer and use it in GitHub Desktop.
Save alexanderbez/ea35747b626f1aa646803bf4a5f056bb to your computer and use it in GitHub Desktop.
A shell function to purge all local git branches that do not exist on remote.
func purgeLocalGitBranches() {
red='\033[0;31m'
echo "${red}Purging local branches no longer found on remote..."
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment