Git Tags

A tag is a pointer to a specific commit. In that regard it is like a branch. Unlike a branch, a tag is static – it doesn’t move when we commit changes. They are often used to tag releases.

A brief note about staging / production.

Staging is:

  • Primarily for testing.
  • Where merging is performed often.
  • For internal use.
  • Where different feature branches are merged into release branch.
  • Where many people have merge rights.

Production is:

  • Stable for production service.
  • For customers.
  • Where merging happens every two to six weeks, or even two to six months.
  • Where usually only staging branch is merged into master branch. A hotfix may be merged directly to production.
  • Where few people have merge rights.

A few notes on semantic versioning.

Semantic versioning follows the form x.y.z where x is the major version, y is the minor version, and z is the patch version. We increment the patch version when a simple bug fix has been released, the minor version when a non-breaking change has been released, and the major when a major, possibly breaking change has been released. When incrementing the major or minor version, reset all the following numbers to zero. After the patch version there can be pre-release information such as 1.1.0-alpha-1.

An alternative version is scheme is date based such as yyyy.mm.patch.

Git has two types of tags, the lightweight tag and the annotated tag. The lightweight tag is just a text file in the .git/refs/tags folder and the annotated tag is the same but also has a git object which stores a tag message and the author and date of tagging. It is recommended to use annotated tags.

To create a lightweight tag, run the following code:

git tag 1.0.0

To create an annotated tag, run the following code:

git tag -a 1.0.0 -m "Tag message here"

The tag name must be unique across the repository. We will get a fatal error if we try to recreate a tag. also we can see a list of current tags by just running:

git tag

If we look at .git/refs/tags/1.0.0 for a lightweight tag, we will see a pointer to a commit object and if do the same for an annotated tag using git cat-file, we will see a pointer to a tag object which points to the commit along with all the other details. Lightweight tags are not pushed to a remote directory which makes sense as there is no git object. Annotated tags are pushed with the following command:

git push --tags

Or to push a single tag:

git push origin 1.0.0

This will push only the tag. Any other changes will need to be pushed separately. Tags will be pulled automatically.

 

Leave a Reply

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