Git – How to delete a tag from the remote
by Riley MacDonald, August 14, 2017

There’s been a few times I’ve needed to remove a git tag from both my local machine and the remote. This is one of those things I can’t seem to remember how to do without looking it up:

# delete the tag from the local repo
git tag -d tag_to_delete
 
# delete the tag from the remote
git push origin :refs/tags/tag_to_delete

A caveat: If someone has pulled the tag from the remote it will exist on their local repository. If they (for some reason) push all tags the tag will end up back on the remote. I avoid pushing all tags to get around this by specifying which tag I want to push:

git push origin tag tag_to_push

Alias function
Since I find myself consistently forgetting this syntax I wrote a bash helper function to handle this for me. See my post on managing dotfiles via git for a quick and easy way to save these types of configurations!

# Delete git tag from local and remote
function delete_git_tag() {
    if [ -z "$1" ]
        then
            echo "missing required argument: please provide tag to delete"
    else
        git tag -d $1
        git push origin :refs/tags/$1
    fi
}
Open the comment form

Leave a comment:

Comments will be reviewed before they are posted.

User Comments:

Be the first to leave a comment on this post!