Git Tag for the Impatient

2023 09 04 head

The development software team has reached a milestone.

A working application with a set of features is available. All tests are green.

The application can potentially be shipped to internal or external customers.

How can you mark this event in the git repository of the application?

Use tags to recognize this state in the list of changes of your shared Git repository.

Listing Your Tags

Listing the existing tags in Git is straightforward. Just type git tag (with optional -l or --list):

$ git tag
v1.0
v2.0

This command lists the tags in alphabetical order; the order in which they are displayed has no real importance.

Creating Tags

Git supports two types of tags: lightweight and annotated.

Annotated tags, however, are stored as full objects in the Git database. They have a check sum. They contain the tagger name, email, and date. THey have a tagging message, and can be signed and verified with GNU Privacy Guard (GPG). It is generally recommended that you create annotated tags, so you can have all this information; but if you want a temporary tag or for some reason do not want to keep the other information, lightweight tags are available too.

Annotated Tags Creating an annotated tag in Git is simple. The easiest way is to specify -a when you run the tag command:

$ git tag -a v1.4.0 -m "1.4.0 (2020.2)"
$ git tag
v0.1
v1.3.1
v1.4.0

The -m specifies a tagging message, which is stored with the tag. If you do not specify a message for an annotated tag, Git launches your editor, and you can type it in.

Sharing Tags

By default, the git push command does not transfer tags to remote servers. You will have to explicitly push tags to a shared server after you have created them. This process is just like sharing remote branches you can run:

git push origin --tags

If you want to correct an error from a tagged version, you should create a branch. If you check out the tag, you are in a detached head mode.

git checkout -b v2-fixex v2.0.0

Thoughts

You can find a lot of information on Stack Overflow. Beware when reading the answers on Stack Overflow that Git commands have changed over time. Select new posts to find the best answers.

The nifty-gritty details can be found in the official Git documentation.

The Pro Git book can be downloaded from Git SCM.