Table of Contents

Git Tags

Tags mark specific commits, usually for releases. A lightweight tag is just a pointer to a commit, while an annotated tag stores the tagger's name, date, and a message, making it more suitable for releases. Tags are immutable markers, unlike branches, so they reliably mark points in history that matter.

Create a lightweight tag with git tag <name>, or an annotated tag with git tag -a <name> -m "message". Both are stored locally by default. Push tags to a remote with git push --tags or push a specific tag with git push origin <tag>. Once pushed, tags should not be moved or deleted, as this breaks history for anyone who pulled them.

$ git tag <name>             # create a lightweight tag
$ git tag -a <name> -m "msg" # create an annotated tag with a message
$ git tag                    # list all tags
$ git show <tag>             # view a tag's commit
$ git push --tags            # push all tags to remote
$ git push origin <tag>      # push a specific tag

The common practice is to tag releases with semantic versioning, like v1.2.3. Annotated tags are preferred for public releases because they preserve metadata. If you accidentally create a tag on the wrong commit, delete it locally with git tag -d <name> before pushing; if it's already pushed, you can ask teammates to delete their copies or simply create a new corrected tag.