Tags work as an additional identifier for a particular incident. And in the case of Git, Tags are used as the reference points in your development workflow and it denotes special events like a new version release or new commit. You can create a new tag to give a reference for your newly launched version. Tagging helps you in identifying the particular commit or release of your code in past.
If you want to create Git tags, then you should know that there are two types of Git tags:
- Annotated tags
- Lightweight tags
Annotated tags are tags with a description while lightweight tags don’t include any description. We will see how to create both of them one by one.
Why should you create tags or what are the benefits of tags?
- When you want to put a part of code or code point for future use reference. The tag will help you in identifying that part.
- While creating a stable version of your code or release point.
Now let’s see how you can create tags.
- To create a git tag, we use the “git tag” command and then specify the name of the tag. For example:
git tag [tagName]
So if you are creating a new tag for your latest launch then you can execute:
git tag v1.4
Next, you can run the “git tag” command to see if you have successfully created the tag or not. This syntax will list all the existing tags.
- If you want to create a tag with a message then you can execute the following command.
git tag -a [tagName] -m “Your message here”
For example:
git tag -a v1.4 -m "This is the new release"
You can even verify your tag by using the following command:
git tag -n
This will display all the existing tags with messages.
- Your git push command will not be pushed to your remote repository automatically. And to push them you have to execute the following command:
git push --tags