Why Git-Tag is important for Release

What’s the difference between tags and branches? The workspace is (almost always) associated with a branch, called master by default. When it is, a commit will automatically update the master reference to point to that read more…

new commit; in other words, branches are mutable references

What is Git Tag?

A tag, on the other hand, is created to point to a specific commit and thereafter does not change, even if the branch moves on. In other words, tags are immutable references.

Git has two flavours of tags;

  • annotated and
  • non-annotated.

When using them, there is little difference between the two; both will allow you to refer to a specific commit in a repository. An annotated tag creates an additional tag object in the Git repository, which allows you to store information associated with the tag itself. This may include release notes, the meta-information about the release, and optionally a signature to verify the authenticity of the commit to which it points.

 

Why use Git tag?

Git tags are like milestones, markers or a specific point in the repo’s history marked as significant. Tags are usually used to mark stable releases or achievement of very important milestones.

Tags can help the users of the repo to easily navigate to the important parts of the code history like release points. For example, on Github, you can easily grab archive of “tags” in the current repo.

 

Commands dealing with Tags

List tags:
git tag

Search in tags:
git tag -l v1.*

That will display tags starting with “v1.” – use regex and your common sense to do complex queries. This can help you narrow down your query in case you have plenty of tags in the repo.

View a tag:
git show v1.4

Note: The command doesn’t have “tag” in it. 🙂

Adding tags:
git tag -a v1.0.0 -m ‘version 1’

The “-a” denotes an annotated tag – means it’s stored as a full object in the git database where as a non annotated tag is just a pointer to a specific commit. Just drop the “-a” to create normal tags. The “-m” option is of course obvious, it allows you to add a message to the annotated tag.

Adding Tags later:
git tag -a v1.2 9fceb02

This will add the “v1.2” tag to the commit marked by “9fceb02”. “git log” will help you get the checksum of the commit.

Pushing Tags to remote branch:
git push –tags

PS: Git tags are not pushed automatically with generic “git push” command. You must push the tags separately.

Deleting a tag:
git tag -d v1.0.0

That will delete the tag v1.0.0.

These are the very common uses of Git tags. Look at the git manual for more complex stuff you can do with taggin

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.