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:
E.g. you can do:
To push your local
some-other-branch
toorigin
'syet-another-name
branch even though your working copy hassome-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.)