In Git Repository, tags can be listed by using the Git Commands ie., ‘git tag’. Whenever you want to work with the list tags in git first make sure that the latest list from the remote repository has been fetched or not. Users require the git list tags of the repository to discover the needed commit point.
You can find different ways to obtain the list of git tags of the local and remote repository. In this tutorial, we have compiled various ways to find out the list git tags on your repository easily.
- How to List All Tags in Git?
- List Local Git Tags
- List Remote Git Tags
- List and Sort Git Tags
- Sorting most recent Git tags
- Fetching Remote Tags Easily
- Find Latest Git Tag Available
How to List All Tags in Git?
If you want to list all available tags in a project then make use of the git tag command (keep in mind that they will appear in alphabetical order):
$ git tag v1.0 v2.0
This method of listing git tags is excellent for small projects, but bigger projects can have hundreds of tags, so you should require to filter them when searching for an important point in history. You can obtain tags including specific characters by adding an
-l to the git tag command:
$ git tag -l "v2.0*" v2.0.1 v2.0.2 v2.0.3 v2.0.4
Must View: How To Delete Local and Remote Tags on Git
List Local Git Tags
In order to list Git tags, you have to use the “git tag” command with no arguments.
$ git tag v1.0 v2.0
You can also execute “git tag” with the “-n” option in order to have an extensive description of your tag list.
$ git tag -n
Optionally, you can choose to specify a tag pattern with the “-l” option followed by the tag pattern.
$ git tag -l <pattern>
Awesome, you have successfully listed tags on your Git repository!
- How To Checkout Git Tags | How Do You Checkout Latest Git Tag Easily?
- How To Delete a GitHub Repository | Step-by-Step Tutorial on Deleting a Repository in GitHub
- How To Create a Git Branch | Learn Git Create New Branch from Current Branch
List Remote Git Tags
As you already know, Git is a decentralized versioning system. As a result, you may have not fetched some tags that have been made available by other developers on your repository.
In order to list remote Git tags, you have to use the “git ls-remote” command with the “–tags” option and the name of your remote repository.
$ git ls-remote --tags <remote>
For example, if your remote name is “origin”, you will have to execute the following command.
$ git ls-remote --tags origin 53a7dcf1ca57e05d456321b406730b39dc8ed75e refs/tags/v1.0 7a9ad7fd794bf52a11de43aacc6010978e6100d3 refs/tags/v2.0
Note: As you can see, by using the “ls-remote” command, you are presented with tags using the “refs” syntax that was already explained in our previous tutorials.
List and Sort Git Tags
Additionally, you can choose to list your tags and sort them following a lexical or a version sorting.
In order to list Git tags following a lexicographic order, you have to use the “git tag” command with the “–sort=refname” option and an additional tag pattern.
$ git tag -l --sort=refname <pattern>
Sorting by refname is not the only way of sorting Git tags.
You can also choose to sort your tags by versions: this way, your tag names will be treated as version numbers.
In order to list Git tags sorted by version numbers, you have to use the “git tag” command with the “–sort=version:refname” option and an additional tag pattern.
$ git tag -l --sort=-version:refname <pattern>
Sorting most recent Git tags
In order to list and sort Git tags by their latest Git activity, you can use the “git tag” command with the “–sort=committerdate”.
$ git tag --sort=committerdate -l <pattern>
Congratulations, you successfully sorted your Git tags using the sort options!
Fetching Remote Tags Easily
Now that you know that some tags are available remotely, you may want to fetch your tags in order to list them locally.
To fetch tags from your remote repository, use “git fetch” with the “–all” and the “–tags” options.
$ git fetch --all --tags Fetching origin From git-repository 53a7dc..7a9ad7 master -> origin/master * [new tag] v1.0 -> v1.0 * [new tag] v1.0 -> v2.0
Awesome, you fetched your tags from your distant repository!
Now, you can list them easily using the “git tag” command (with no arguments!)
$ git tag v1.0 v2.0
Find Latest Git Tag Available
In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option.
This way, you will be presented with the tag that is associated with the latest commit of your current checked-out branch.
$ git describe <latest_tag>
From this tutorial, you discovered how you can easily list your Git tags, whether they are local or remote.
You also learned that you can use advanced sorting options in order to have your results sorted by recent date or version number.
We have other tutorials on Git tags, make sure to have a read: