Git tags

Published: Tuesday, 27 October 2020

A tag points to a specific commit in a repository. It is often used to label a release or version of code, so that it may be referred to later.

An annotated tag also contains a date, tagger and message. A lightweight tag only includes the commit.

Creating a tag

To add or create an annotated tag, gather or decide on

  • The name of the tag, e.g. the version number
  • A message describing the tag
  • The commit hash, or make sure the repo’s HEAD is at the commit you want to tag.

Then run

git tag -a -m 'first release' v1.0.0

The tag will only existing in the local repo. To distribute the tag, it must be pushed.

git push --tags

Listing tags

To see all tags in a repo, run

git tag

Deleting a tag

To delete a tag run

git tag -d v1.0.0

Before doing this, consider how the tag is being used and whether a new tag is more appropriate.

References