Skip to content

Instantly share code, notes, and snippets.

@smudge
Last active January 26, 2022 16:08
Show Gist options
  • Save smudge/5481a4225c2690a060f76c6a25826703 to your computer and use it in GitHub Desktop.
Save smudge/5481a4225c2690a060f76c6a25826703 to your computer and use it in GitHub Desktop.
Delete all remote git branches
#### Delete all remote git branches
# Primary purpose: When you fork a repo and want a clean slate for your fork.
#### WARNING
# This is REALLY UNSAFE. Don't do this on a shared repo!
# Again: DO NOT DO THIS unless you're really, really sure.
git branch -r | grep -e "origin" | grep -v "origin/main" | awk '{sub(/origin\//,"");print}'| sed 's/^[ *]*//' | sed 's/^/git push origin :/' | bash
### BONUS: Delete all remote tags
# Same warning applies!
# Deletes 1000 at a time
git push origin --delete $(git ls-remote --tags origin | grep -v "{}$" | awk '{sub(/.+refs\/tags\//,"");print}' | head -n 1000)
# Delete all local tags:
git tag -l | xargs git tag -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment