Delete GIT tags from local and remote branch

Problem statement: Recently at work we have been playing around with the concept of automated builds and one build (master build) kicking off builds for multiple projects. The master build that kicked off multiple builds would kick off builds for all projects regardless of whether there were any code changes in that particular project or not. This caused more than a 100 builds with no real code change in them. The builds would also create tags. I wanted to clean up these tags since we were moving away from automated builds for this one project.

Solution: Here's a simple python script to delete tags locally as well as from remote branch.

__author__ = 'ravi'  
from subprocess import call  
import logging as log  
import os

os.chdir('/home/ravi/dev/projects/spiderman')  
for i in range(115, 280):  
    try:
        # Remove locally
        call(['git', 'tag', '-d', '1.0.{}'.format(i)])
    except Exception as ex:
        log.exception(ex)
        pass
    try:
        # Remove from master
        call(['git', 'push', 'origin', ':refs/tags/1.0.{}'.format(i)])
    except Exception as ex:
        log.exception(ex)
        pass

NOTE:

  1. Line #6: Provide the path of the git repo.
  2. Line #7: Change the format and numbers to the tag format and numbers you want to remove.
  3. Please be careful!

Pretty straightforward!