Git Tag
Tags are ref's that point to specific points in Git history. Tagging is generally used to capture a point in history that is used for a marked version release (i.e. v1.0.1). A tag is like a branch that doesn’t change. Unlike branches, tags, after being created, have no further history of commits.
Types of Git Tags
There are two types of tags in git.
- Annotated tag
- Light-weighted tag
Both of these tags are similar, but they are different in case of the amount of Metadata stores. If you are pointing and saving a final version of any project, then it is recommended to create an annotated tag. But if you want to make a temporary mark point or don't want to share information, then you can create a light-weight tag.
1. Annotated Tags
Annotated tags are tags that store extra Metadata like developer name, email, date, and more. They are stored as a bundle of objects in the Git database. All this data is important for a public release of your project.
Similar to commits and commit messages Annotated tags also include a more descriptive tag-message or annotation.
Syntax:
git tag <tag name> -m "Tag message"
2. Light-Weighted Tags
Lightweight tags are the simplest way to add a tag to your git repository because they store only the hash of the commit they refer to. They are created with the absence of the -a, -s, or -m options and do not contain any extra information.
Lightweight tags are essentially "bookmarks" to a commit, they are just a name and a pointer to a commit, useful for creating quick links to relevant commits.
Syntax:
git tag <tag name>
Additional Commands
Listing Tags
The git tag
command is used to list all the available tags from the repository.
Example:
git tag
Output:
projectv1.0
projectv1.1
projectv1.2
Tag Details
The git show <tag identifier>
cammand is used to display the details of a particular tag.
Example:
git show projectv1.0
Output:
tag projectv1.0
Tagger: Gitopia <tutorial@gitopia.org>
Date: Sat Oct 23 20:19:12 2021 +0530
version 1.0
commit 9fceb02d0ae598e95dc970b74767f19372d61af8
Author: Gitopia <tutorial@gitopia.org>
Date: Sat Oct 23 20:19:12 2021 +0530
Change version number
Pushing Tags
We can push tags to a remote server project. It will help other team members to know where to pick an update. It will show as release point on a remote server account. The git push command facilitates with some specific options to push tags.
You can git push
the tag individually, or you can run git push --tags
which will push all tags at once. It can be done similarly to pushing the branches.
Example:
git push origin projectv1.0
Deleting Tags
Deleting tags is a straightforward operation. Passing the -d option and a tag identifier to git tag will delete the identified tag.
Example:
git tag -d projectv1.1
You can learn more about the
git tag
command and its options in git-scm's documentation.