...

How to Use Git Tags

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.

  • How to Add a Lightweight Tag
  • How to Add an Annotated Tag
  • Now That You Know All About Git Tags…

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:

christopher@server $ git show v1.0
commit 0659595374f673bdffcc5a9d8b08efb145834132
Author: ChristopherM <chris@example.com>
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:

christopher@server $ git tag -a v1.2 -m “my version 1.2“
christopher@server $ git show v1.2
tag v1.2
Tagger: ChristopherM <chris@example.com>
Date: Wed Nov 1 16:08:36 2017 -0400 my version 1.2 commit 0659595374f673bdffcc5a9d8b08efb145834132
Author: ChristopherM <chris@example.com>
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…

Check out these other resources from the Support Center:

  • Using Git to Publish Files
  • How to Create Your Own Git Server
  • Git Hooks (and How They Work)

Discover more from WIREDGORILLA

Subscribe now to keep reading and get access to the full archive.

Continue reading