Skip to content

How to Create Git tags

Covers
Git
Versions & support
About Git →

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.

  1. 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.

  2. 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.

  3. 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 
    

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top