How to List All Tags in Git

Azhar Bashir Khan Feb 02, 2024
How to List All Tags in Git

This tutorial will teach us how to list all tags in Git.

Git is a version control system that tracks changes in a project directory using the Git repositories. The changes done to the files are tracked in the Git repositories using commits.

Using tagging, we can mark important checkpoints of the commit history of our Git repository. We can use the Git command git tag to list the tags in the Git repository.

We will now illustrate this with an example.

List All Tags in Git

We can list the tags we would have previously added using the Git command git tag.

We need to execute the Git command git tag to list all tags in our Git repository.

$ git tag
v1.0
v2.0

We can also search for tags that match a particular pattern.

Suppose we have added tags for the release named v1.2.4 in our project Git repository. We can search for all the tags matching the pattern v1.2.4 in our Git repository using the Git command git tag with the -l command option as follows:

$ git tag -l "v1.2.4*"
v1.2.4
v1.2.4-rc0
v1.2.4-rc1
v1.2.4-rc2
v1.2.4-rc3

We can also list tags from the remote Git repository. We can use the Git command git ls-remote with the --tags command option.

Thus, to list tags of the remote repository referred to by origin, we can execute the command as follows:

$ git ls-remote --tags origin

232a7dcf1ca57e05d892311b406730b39dc8ed75e        refs/tags/v1.0
111ad7fd794bf52a11de43ddaa6010978e6100d3a        refs/tags/v2.0

Thus, we have learned how to list all tags in Git.

For more information, please visit:

  1. git-tag
  2. git-ls-remote

Related Article - Git Tag