Skip to content

Instantly share code, notes, and snippets.

@kingster
Created June 20, 2016 22:21
Show Gist options
  • Save kingster/0f08c50e3dc1251a16298cea4e009ad7 to your computer and use it in GitHub Desktop.
Save kingster/0f08c50e3dc1251a16298cea4e009ad7 to your computer and use it in GitHub Desktop.
cleanup all git tags
#!/bin/bash
# This script will delete *all* local and remote tags from any git repo you run
# it in starting with "release"
#
# This script will not delete branches; just tags.
set -e
REMOTE='origin'
# Requires git 1.7.+
# Verify that the remote is actually GitHub.
#if [ `git remote show $REMOTE | grep github.com | wc -l` == "0" ]; then
# echo "The '$REMOTE' remote doesn't appear to be GitHub. Please edit"
# echo "this script and set the REMOTE variable at the top to the name of"
# echo "your git remote that points to GitHub."
# echo
# exit 1
#fi
echo "--> Cleaning up tags"
# First, delete all old local tags.
git tag -d `git tag | grep "^[release]" | xargs`
# Now fetch all remote tags so we'll know which ones to delete.
git fetch --tags $REMOTE
tags=`git tag | grep "^[^v]" | xargs`
# Delete all old remote tags.
if [ "$tags" != "" ]; then
git push -v --delete $REMOTE $tags
fi
# Re-delete all old local tags.
git tag -d $tags
echo "--> Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment