A Guide to Git Tag Types and Usage
We know that projects in GitHub or GitLab are classified into modules and each module is assigned to specific users. For the ease of developers, Git allows the user to label the project with the version/message at some points to be remembered. It is beneficial for developers in clearer documentation, easier version management, simplified collaboration, and improved traceability. It can be done with the help of Git tags.
Today’s tutorial is about Git tags and the usage of their various types with the below-provided outline:
What are the Types of Git Tags?
As described earlier, Git tags are the labels that are used to remember/show the different versions of the projects. It is categorized into two types, such as Lightweight and Annotated tags which are described in the following table:
Types | Description |
Lightweight Tags | A simple tag that requires no extra details and is useful for quick reference in Git projects. |
Annotated Tags | It is the advanced type of Git tag that contains extra data/information like name, date, email, and message (optional). |
Let’s move ahead and create these two tags in Git Bash practically.
How the Lightweight Tag is Created in Git?
To create the Lightweight tag in Git, perform the below-provided steps.
Step 1: Move to Git Repository
Open Git Bash and move to the Git repository via the “cd” command:
Step 2: Switch Branch
After that, switch to the desired branch in which you are working. To do so, use the following command:
In our scenario, we have switched to the “module-1” branch.
Step 3: Create a Lightweight Tag
For creating the lightweight tag, use the “git tag” command and specify the quick reference i.e. “v1.0”:
The project has been labeled with the tag v1.0.
Step 4: List Available Tags
To list all available tags, simply type the “git tag” command:
From the above output, you can see that the newly created tag is available “v1.0”.
Step 5: Show Tag Details
Additionally, the user can list the detailed information about the created tag using the “git show” command along with the tag label:
How an Annotated Tag is Created in Git?
Likewise, to create the annotated tag in Git, walk through the below-provided steps.
Step 1: Create Annotated Tag
To create the annotated tag in Git, type the “git tag” command with the “-a” flag and specify the message via the “-m” flag:
The provided annotated tag “v1.1” has been created.
Step 2: List Tags
List down the available tags using the “git tag” command for verification:
As you can see, our annotated tag “v1.1” exists in the list.
Step 3: Check the Results
Similarly, to display the detailed information of the created tag, execute the “git show” command and specify the tag name:
This is how the tags are created in Git Bash.
Bonus Tip: How to Remove a Tag in Git?
To remove any created tag in Git, use the “-d” flag with the “git tag” command and specify the tag name as performed below:
According to the above-provided output, the tag named v1.0 has been deleted successfully.
Conclusion
Git tags are the labels that are considered to emphasize the version/names at specific points of the committed changes. These are classified into two types, such as Lightweight and Annotated tags. Lightweight is the simple tag for labeling the quick reference or version. To create it, simply type the “git tag” command. Annotated tags contain extra data/information like name, date, email, and an optional message. To create it, use the “git tag -a” command, specify the tag name, and write a message with the “-m” flag if required. This guide has enlightened the Git tagging strategies in Git Bash.
Source: linuxhint.com