Git tags are an important tool for marking specific versions in a project. They are often used to identify releases or milestones. This article will explain how to create, view and manage tags in Git.
create tags
To create a tag in Git, use git tag
the command. There are two types of tags: lightweight tags and annotated tags.
lightweight label
A lightweight tag is a static reference to a specific commit, it's just a pointer to a specific commit. Creating a lightweight tag is as simple as specifying the tag name and the checksum of the commit.
$ git tag <tag_name> <commit_checksum>
Example:
$ git tag v1.0.0 2f45c6a
Annotation label
An annotated tag is a Git object that contains information about a tag, such as tag name, tag creator, date, comments, etc. When creating a note tag, you can add some extra information.
$ git tag -a <tag_name> -m "Tag message"
Example:
$ git tag -a v1.0.0 -m "Initial release"
view label
To see the tags that have been created, you can use git tag
the command.
$ git tag
This command will list all tag names.
If you want to see the details of a specific label, you can use git show
the command.
$ git show <tag_name>
Example:
$ git show v1.0.0
share label
By default, tags are not automatically pushed to remote repositories. If you want to share tags, you need to git push
push them explicitly with the command.
$ git push origin <tag_name>
Example:
$ git push origin v1.0.0
To push all tags at once, use --tags
option.
$ git push origin --tags
delete label
To delete a local label, use git tag -d
the command.
$ git tag -d <tag_name>
Example:
$ git tag -d v1.0.0
To delete a tag in a remote repository, use git push
the command and specify --delete
options.
$ git push origin --delete <tag_name>
Example:
$ git push origin --delete v1.0.0
Recommended Use of Labels
-
v1.0.0
Stable releases are tagged with semver numbers such as . -
When creating a label, it is a good idea to add a relevant note along with it to better understand the purpose and content of the label.
-
For each important commit or milestone version, a corresponding tag should be created to better track the progress of the project.