September 11, 2013

Deleting remote tags with Git

I really like Git. It is an awesome tool, and since it's also the VCS that got me into managing my source code (and other stuff), I've never really felt it was that hard to learn.

But then the other day I suddenly needed to delete a remote tag.

Deleting tags locally is dead simple:



There. Simple, logical and straightforward. Deleting tags on a remote on the other hand, is a bit more "confusing", first and foremost because you're not going to be using the git tag command at all. Instead you'll be using git push.

Yea, that makes a lot of sense to me. It might make perfect sense to a hardcore Git user, but to someone like me it feels a bit "meh".

In the manual for git push we find this little gem:

git push origin :experimental
Find a ref that matches experimental in the origin repository (e.g. refs/heads/experimental), and delete it.

Aha! Since our tag is "a ref" all we apparently have to do is push nothing to the ref, and Git will delete the ref on the remote. YAY! So in order to delete some_tag, we do:



And I can report that it does indeed work. The tag is removed from the remote, and all is well. I can't say I really like this method. I would have much preferred that remote tags were deleted using the git tag command, perhaps by adding a --remote option or something like that, but hey, what do I know.

At least now I've learned that in order to delete remote tags, I need to push nothing over the wire. No delete options or delete commands. Just pure and utter emptiness. I've learned my lesson.