git tag

Mark an important point in your repository history

The git tag command is very useful for marking an important point in your repository's history. The most common use-case for this command is to mark a version or release point in your code.

Creating a new tag and commit

You would type the following in your terminal to use this command:

$ git tag -a v1.1 -m "Version 1.1"

This would be used instead of git commit -m "Version 1.1" and create a new commit and assign the tag v1.1 to it at the same time.

Tagging an old commit

If you want to assign a tag to a past commit, you can do so using this command:

$ git tag -a "v1.0" 1234abc

Where 1234abc is your previous commit reference.

Searching and using tags

You can view a list of previously added tags using the following command:

$ git tag

v1.1
v1.0

You'll see a full list of previous tags in the repository. If you have a large number of tags, you can even use a simple wildcard such as:

$ git tag -l "v1*"

v1.1
v1.0

To view all tags starting with v1.

You can then use any tag that exists in git operations, in exactly the same way that you might use a commit reference, such as git checkout or git show.