How to Use Git Tags

How to use Git Tags

If you don’t need cPanel, don't pay for it. Only pay for what you need with our Cloud VPS solutions

check markCentOS, Debian, or Ubuntu    check markNo bloatware    check markSSH Key management made easy

Throughout the life of your project, you will reach various milestones. With Git, we mark significant improvements and modifications with commits, but often there will be events that will require more annotation, such as version changes. In this article, you’ll learn about how to use tags in Git to mark significant events in the life of your project.

If you are new to Git, be sure to check out our guide on learning Git.

Before proceeding with tagging, we will want to highlight the different types of tags available. There are two main tag types: lightweight and annotated.

For a quick tag, merely a reference to a certain commit, the lightweight tag is sufficient. However, the annotated tag is recommended because it contains more detailed metadata that might be helpful to you later.

How to Add a Lightweight Tag

Adding a lightweight requires only a quick and easy “tag” command with no options:

git tag v1.0

Now, a tag of “v1.0” will reference the most recent commit. To use this tag as a reference use this command:

git show v1.0

This output of this command will be a display of the commit referenced and changes that were made in that commit. The below command line output demonstrates this:

[email protected] $ git show v1.0
commit 0659595374f673bdffcc5a9d8b08efb145834132
Author: ChristopherM <[email protected]>
Date: Wed Nov 1 10:13:25 2020 -0400

Improved database connection

How to Add an Annotated Tag

In order to add an annotated tag, you will use the same “tag” command. However, there are a few options to add in this case. Use the -a option to make this tag “annotated” and the -m command to provide the tag with a message (similar to a commit message).

git tag -a v1.2 -m "my version 1.2"

Then, to show the output of this tag’s reference, us the Git “show” command again, as in the below command line instance:

[email protected] $ git tag -a v1.2 -m “my version 1.2“
[email protected] $ git show v1.2
tag v1.2
Tagger: ChristopherM <[email protected]>
Date: Wed Nov 1 16:08:36 2017 -0400

my version 1.2

commit 0659595374f673bdffcc5a9d8b08efb145834132
Author: ChristopherM <[email protected]>
Date: Wed Nov 1 10:13:25 2020 -0400

Added new test feature

Well done! You now know how to add tags with Git.

For more exhaustive detail, check out the complete documentation on git tags.

Now That You Know All About Git Tags…

CM
Christopher Maiorana Content Marketing Writer

Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.

More Articles by Christopher

Was this article helpful? Let us know!