How to REALLY remove a tag on git / SourceTree

6.1k views Asked by At

I know how to delete a tag from SourceTree. Just right-click, delete, and tick "remove tag from all remotes." It then executes the following (and I'm omitting the flags -c diff.mnemonicprefix=false -c core.quotepath=false for readability):

git tag -d my_tag
git push -v origin :refs/tags/my_tag

This works.

Here is the problem.

Some time later, one of the other developers will push their feature branch to origin, and SourceTree will automatically push all local tags to the remote server. This will recreate the tag I just deleted.

I know the idea is that tags are not "supposed" to be deleted, e.g. tagged releases, but sometimes mistakes happen.

Any advice?

1

There are 1 answers

0
DontPanic345 On

The only solution I have found is to simply ask all the other developers to remove their local copies of the tags after you have deleted them from the remote. I found a script help here.

To put it simple, if you are trying to do something like git fetch -p -t, it will not work starting with git version 1.9.4.

However, there is a simple workaround that still works in latest versions:

git tag -l | xargs git tag -d # remove all local tags
git fetch -t                  # fetch remote tags

A one liner can be written as:

git tag -l | xargs git tag -d && git fetch -t

Alternative, you can add a new alias to your ~/.gitconfig file to make things shorter:

in ~/.gitconfig

[alias]

     pt = !git tag -l | xargs git tag -d && git fetch -t 

Now, you can simply call pt alias to prune local stale tags:

git pt