As you progress in project development, it is indeed optional to learn Git tagging. But knowing how to use tags in Git may serve as a future reference. Git tagging is a step in project development to mark a new milestone of that project. It’s top priority to is to mark versions of your project.
Why are they used?
Let’s say you’ve finished developing your entire project. And you want to mark this part of your development as fully-operational. To mark the current state of your project you have to use tags. Most lead developers tag their projects first before releasing them to the public. This is where the “version control” part of VCSs are implemented. Lead developers would tag projects by version names.
v1.0, v1.2.1, v1.2.2…
These tags then represent a part of the project that is stable and can therefore be released to the public. Some versions may also differ in functionality and bugs with each new version.
What else do tags do?
Tags are really just used to mark different versions of your project. However, there are two different tags used for different purposes.
1. Lightweight Tags
Lightweight tags are the default kind of tags. They only mark versions of your project’s commits and declare its version.
2. Annotated Tags
Annotated tags are just like lightweight tags but with more information. With annotated tags, you can specify a message along with that tag, sign with a GPG key (depending on your email address associated), and other meta-descriptions.
How to tag a commit?
Tagging requries the lead developer’s approval before tagging the project’s latest commit. This ensures that the project’s state is now stable and can be released to the public. Then, the lead developer is now responsible for tagging the latest commit. The lead developer must now open the directory of his/her local repository and input into the command line:
#Lightweight tagging git tag version_name #Annotated tagging git tag -a version_name -m "Message"
The lead developer must decide on which tag to use before tagging. After that, the tag is now successfully marked on the side of the latest commit’s SHA1. However, this is only done on the local repository of the lead developer. Therefore, the lead developer has to commit and push the new tag to the origin/master branch.
[OPTIONAL] To check the success of the new tag enter into the command line below:
NOTE: Tags are only found and used on the origin/master branch.
The process of pushing tags to the origin/master branch is the same for any commit. Learn how to create commits here.
Finally, check if the new tag is found at the latest commit of your origin/master branch.