Remove a Git Tag From Github When There is Also a Branch of the Same Name

I have been using git and Github off and on for a while now but I’ve never really learned much about it.

Today, I mistakenly added a tag with the same name as a branch and pushed it to Github. I was able to get rid of it locally but I was pulling my hair out trying to figure out to remove it from Github. I finally stumbled on the solution so here is what I learned.

Removing a git tag:

git tag -d <tag>

Removing a git branch:

git branch -d <branch>

Deleting a tag or branch from Github:

git push origin :<tag or branch>

Deleting a tag (with the same name as a branch) from Github:

git push origin :refs/tags/<tag>

Deleting a branch (with the same name as a tag) from Github:

git push origin :refs/heads/<branch>


To decipher some of the alchemy, the reason *why* this works is that git push takes the arguments:

git push [options] <repository> <refspec>

E.g. you can do:

git checkout some-branch
git push origin some-other-branch:yet-another-name

To push your local some-other-branch to origin's yet-another-name branch even though your working copy has some-branch checked out.

But if you supply an *empty* source at the left-hand side of the ":" you'll push an empty refspec to an existing remote branch, so you'll delete it.

Thank you very much, this helped me out. (I accidentally made a tag with the same name as a branch, which broke GitHub for Mac's ability to push commits, and I wasn't sure how to delete the tag because its name matched a branch name until this post.)

Leave a comment

About Mr. Muskrat

user-pic I'm married with 2 girls. By day, I work as a Senior Design Engineer (full time Perl programmer) for EFJohnson Technologies, a Land Mobile Radio company, in the Dallas/Fort Worth area. By night, I play various games as the mood strikes me. (Lately it's CPAN smoke testing.)