Tags management in Git

There are two kinds of tags in Git:

  • Lightweight tags — just a tag name pointing to a specific commit.
  • Annotated tags — a object stored in the Git database. It contains the tagger name, email, date and a tag name and message. It can be signed and verified with GNU Privacy Guard(GPG).

Generally it is recommended to create annotated tags so you have all the information. Lightweight tags can be used for temporary purposes.

Create a tag for a commit

# Create a lightweith tag "v1.0" for HEAD.
$ git tag v1.0

# Create an annotated tag for HEAD with ""-a" option.
# -a, this is an annotated tag which can include other information in an object,
#     such as message, name, email
$ git tag -a v1.0 -m "Formal version v1.0"

# Create a tag for commit 06d49a9
$ git tag v1.0 06d49a9

Note: By default, git push does not push tags to the remote repository, you need to explicitly push them:

# Push a tag "v1.0" to remote repository
$ git push v1.0

# Push all tags to remote repository
$ git push --tags

List tags

# List all tags
$ git tag

# Or you can use -l or --list to list all tags matching a pattern
$ git tag -l "v1.0*"
v1.0
v1.0.1

Delete a tag

To delete a tag, use below command:

# Delete a tag
# -d, delete a tag with its name
$ git tag -d <tagname>

Examples

$ git tag -d v1.0

Resources