Git tag


Git tags are extremely useful when marking a milestone or release. Here are some commands I use when working with them.

Create

To create a lightweight tag from the current commit:

# git tag <tagname>
$ git tag v1.0.0

To create an annotated tag from the current commit:

# git tag -a <tagname> -m <message>
$ git tag -a v1.0.0 -m "First release"

The difference between lightweight tags and annotated tags is a lightweight tag uses the existing commit whereas an annotated tag creates a new commit checksum.

To tag a different commit:

# git tag <tagname> <hash>
$ git tag v0.1.0 a1b2c3d

View

To list all tags:

$ git tag

To show contents of a tag:

# git show <tagname>
$ git show v1.0.0

Push

To push a tag to the remote repository:

# git push <remote> <tagname>
$ git push origin v1.0.0

To push all tags to the remote repository:

# git push <remote> --tags
$ git push origin --tags

Delete

To remove a tag from the local repository:

# git tag -d <tagname>
$ git tag -d v1.0.0

To remove tag from the remote repository:

# git push <remote> :refs/tags/<tagname>
$ git push origin :refs/tags/v1.0.0