Git Tagging Cheatsheet
Git tags are similar to regular code. One add and deletes tags locally. At some point they are pushed to a remote repository. The syntax is mostly similar to what you do with code.
The best references for git tagging are in the git book, specifically 2.6 Git Basics Tagging and 10.3 Git References. The built-in help
git tag --help is also useful, especially the section on re-tagging.
When reading these, keep in mind that Git has two types of tags. But “tag” almost always means “annotated tag.” The other type of tag, “lightweight tags” might have some use for some tools that need throwaway tags, but in most cases can be ignored. Everything below is for the common case of annotated tags.
|List All Tags||
|Add A Tag Locally||
|Add a Tag at Specific Commit||
|Delete a Tag Locally||
|Redoing a Tag Locally||
|Push a Tag to Remote||
|Push all Local Tags to Remove||
|Delete a Tag on Remote||
|List Tags as References||
Retagging and Deleting Remote Tags
Deleting remote tags is not listed in any documentation I have read. The command listed above I found from this post. The
git tag --help has a nice discussion on retagging, but deleting a remote tag is somewhat similar to deleting a remote commit. You can erase a commit, there are sometimes good reasons to do it, but it’s not going to be easy and there is strong possibility of side effects. The same goes for tags.
That said, in most cases you won’t actually need to delete remote tags, unless they are truly just junk. If the tags are for releases, it most likely the tag isn’t bad but the actual release is problem. In which case, make a new release, and a new tag and fail forward. Or your build release system broke. To rekick the system, it’s fine to retag the release using the
-f -a flags, and another
git push origin.