Skip to content

Instantly share code, notes, and snippets.

@hugorodgerbrown
Last active January 12, 2021 21:28
Show Gist options
  • Save hugorodgerbrown/5f3288cf50161a88fa44ca49c89d7ff6 to your computer and use it in GitHub Desktop.
Save hugorodgerbrown/5f3288cf50161a88fa44ca49c89d7ff6 to your computer and use it in GitHub Desktop.
Git - remove all remote tags
# Sometimes tags get out of control - git apps (Tower, SourceTree, Github) can often add
# tags automatically (e.g. when merging branches) and over time your remote repo can become
# cluttered with irrelevant tags. The easiest way to clean this up is to get your local
# repo in order, delete all the remote repo tags, and then repush from local.
# Dump all local tags into a text file
git tag -l > tags.txt
# Remove all the tags you want to keep, leaving only those for deletion.
[vim | emacs | micro | sublime | ...] tags.txt
# Delete all the tags that are left
xargs git tag -d < tags.txt
# Clean out all tags from the remote repo (origin in this case)
git ls-remote --tags origin | awk '/^(.*)(\s+)(.*[a-zA-Z0-9])$/ {print ":" $2}' | xargs git push origin
# Repush all the local tags
git push origin --tags
# NB this is a HIGH RISK operation - proceed with caution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment