DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How To Use Git Cherry-Pick to Apply Selected Commits
  • Top 35 Git Commands With Examples
  • Git Reset HEAD
  • Git Tags vs AWS Tags: A Tag-Tastic Showdown!

Trending

  • How to Convert Between PDF and TIFF in Java
  • The Role of Functional Programming in Modern Software Development
  • Key Considerations in Cross-Model Migration
  • Transforming AI-Driven Data Analytics with DeepSeek: A New Era of Intelligent Insights
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Git Tags: Version Control Made Easy

Git Tags: Version Control Made Easy

Git tags are a simple and effective way to make sure you can keep track of the different versions of your code, and an important quality of Git's version control.

By 
Kristina Garcia Francisco user avatar
Kristina Garcia Francisco
·
Jun. 12, 18 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
28.4K Views

Join the DZone community and get the full member experience.

Join For Free

Tags are a simple aspect of Git: they allow you to identify specific release versions of your code. You can think of a tag as a branch that doesn't change. Once it is created, it loses the ability to change the history of commits.

There are two types of tags in Git: annotated and lightweight. Both of them will allow you to refer to a specific commit in a repository, but they differ in the amount of metadata they can store.

Annotated tags store extra metadata such as author name, release notes, tag-message, and date as full objects in the Git database. All this data is important for a public release of your project.

Tags can also include a more descriptive tag-message or annotation much like a commit message when you are about to merge. Usually, this is achieved by using (-a for annotation):

$ git tag -a v1.0.0 

Executing this command you will create a new annotated tag identified with version v1.0.0. The command will then open up your commit editor so that you can fill up the metadata.

In case you wanted to add a tag-message you can pass the -m option, this is a method similar to git commit -m.

$ git tag -a v1.0.0 -m "Releasing version v1.0.0" 

Lightweight tags are the simplest way to add a tag to your Git repository because they store only the hash of the commit they refer to. They are created with the absence of the -a, -s, or -m options and do not contain any extra information.

Lightweight tags are essentially "bookmarks" to a commit, they are just a name and a pointer to a commit, useful for creating quick links to relevant commits. By Bitbucket tutorials

To create a new lightweight tag execute the following command:

$ git tag v1.0.0 

Additional Commands

Listing tags - git tag
Use the command whenever you want to list all the existing tags, or you could filter the list with git tag -l 'v1.1.*', where * acts as a wildcard. It will return a list of tags marked with v1.1.

You will notice that when you call you do not get to see the contents of your annotations. To preview them you must add -n to your command: git tag -n3.

$ git tag -l -n3 v1.0 Release version 1.0 v1.1 Release version 1.1 v1.2 Release version 1.2 

The command lists all existing tags with maximum 3 lines of their tag message. By default -n only shows the first line.

Tag details - git show <tag_identifier>
This command presents you with tag details and information from the commit that was tagged.

$ git show v1.0 tag v1.0 Tagger: Kolosek Date: Fri May 11 10:45:33 2018 +0100 Release version 1.0 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iMTvhAA... -----END PGP SIGNATURE----- commit 7d44b6bb8abb96dee33f32610f56441496d77e8a Author: Kolosek Date: Fri May 11 9:50:13 2018 +0100 Edited the Login form ... 

It prints the author's name, creation date, message, GnuPG signature if present and the information about the referenced commit. If the tag is lightweight, the output will be limited to the information about the referenced commit.

Editing tags - git tag -a -f <tag_identifier> <commit_id>
If you try to create a tag with the same identifier as an existing tag, Git will throw an error: fatal: tag 'v1.0' already exists.

Instead of having to delete it and re-add the tag you can simply replace it while keeping the existing description. Choose the place in your commit history with <commit_id> where you want the tag moved to and add -f or -force to your command.

Remember to alert your team members when you "force" a change like this. If they still have an "old" version of the tag, it may cause conflicts when they try to push to the server!

If you have already pushed the tag to the server and want to fix that, first make sure your local version of the tag is correct before you run the following command: git push origin -f --tags.

Deleting tags - git tag -d <tag_identifier>
Generally, there is no reason to delete the tags because they are inexpensive and don't use any resources unless you have mistakenly created a tag pointing to the wrong commit.

In case the tag has been already pushed and you need to remove it from remote repository run: $ git push origin :v1.0.

Publishing tags - git push <location> <tag_identifier>
A tag is just a reference to your local repository and it is not automatically pushed to the remote repository with the rest of the code. Instead, you can git push the tag individually, or you can run git push --tags which will push all the tags at once. It can be done similarly to pushing the branches:

$ git push origin v1.0 

Sorting tags - git tag --sort=<type>
When looking at a project with lots of tags, using the sort option can come in handy. Supported types are:

  • refname (sorts in a lexicographic order),
  • version:refname or v:refname (here tag names are treated as versions).
git tag -l --sort=-version:refname "v*" 

Here we are listing all tags which name starts with "v" by their versions.

Isn't git tag the same as #tag in social media, but in its own way? It helps us return and list all our previous release!

Subscribe to our future article releases! We will make it sure to git tag them for you!
Git Version control Commit (data management) Command (computing)

Published at DZone with permission of Kristina Garcia Francisco, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Use Git Cherry-Pick to Apply Selected Commits
  • Top 35 Git Commands With Examples
  • Git Reset HEAD
  • Git Tags vs AWS Tags: A Tag-Tastic Showdown!

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!