Skip to content

Instantly share code, notes, and snippets.

@p-karanthaker
Last active November 16, 2020 10:10
Show Gist options
  • Save p-karanthaker/86cf0273f870c6cbe81219cdd55fcd2e to your computer and use it in GitHub Desktop.
Save p-karanthaker/86cf0273f870c6cbe81219cdd55fcd2e to your computer and use it in GitHub Desktop.
Deletes local git branches that are not on remote.
git fetch -p && for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); 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