740

In my repository, I have created tags using the following commands.

git tag v1.0.0 -m 'finally a stable release'
git tag v2.0.0 -m 'oops, there was still a major bug!'

How do you list all the tags in the repository?

Léo Léopold Hertz 준영
  • 119,377
  • 159
  • 417
  • 655

10 Answers10

1049
git tag

should be enough. See git tag man page


You also have:

git tag -l <pattern>

List tags with names that match the given pattern (or all if no pattern is given).
Typing "git tag" without arguments, also lists all tags.


More recently ("How to sort git tags?", for Git 2.0+)

git tag --sort=<type>

Sort in a specific order.

Supported type is:

  • "refname" (lexicographic order),
  • "version:refname" or "v:refname" (tag names are treated as versions).

Prepend "-" to reverse sort order.


That lists both:

  • annotated tags: full objects stored in the Git database. They’re checksummed; contain the tagger name, e-mail, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG).
  • lightweight tags: simple pointer to an existing commit

Note: the git ready article on tagging disapproves of lightweight tag.

Without arguments, git tag creates a “lightweight” tag that is basically a branch that never moves.
Lightweight tags are still useful though, perhaps for marking a known good (or bad) version, or a bunch of commits you may need to use in the future.
Nevertheless, you probably don’t want to push these kinds of tags.

Normally, you want to at least pass the -a option to create an unsigned tag, or sign the tag with your GPG key via the -s or -u options.


That being said, Charles Bailey points out that a 'git tag -m "..."' actually implies a proper (unsigned annotated) tag (option '-a'), and not a lightweight one. So you are good with your initial command.


This differs from:

git show-ref --tags -d

Which lists tags with their commits (see "Git Tag list, display commit sha1 hashes").
Note the -d in order to dereference the annotated tag object (which have their own commit SHA1) and display the actual tagged commit.

Similarly, git show --name-only <aTag> would list the tag and associated commit.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • 6
    It's probably worth adding that -m or -F implies -a (if non of -a, -s or -u are supplied explicitly. You can't have a tag message without creating a 'proper' tag object. – CB Bailey Jun 30 '09 at 18:05
  • 1
    Note to self: with this upvote, I pass 800000 (Aug 31st, 2018) on Stack Overflow, one year and one month after [reaching 700000 (Aug 6th, 2017)](https://stackoverflow.com/a/33066676/6309). – VonC Aug 31 '18 at 06:57
197

To list tags I prefer:

git tag -n

The -n flag displays the first line of the annotation message along with the tag, or the first commit message line if the tag is not annotated.

You can also do git tag -n5 to show the first 5 lines of the annotation.

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
finn
  • 2,687
  • 1
  • 18
  • 12
51

Also git show-ref is rather useful, so that you can directly associate tags with correspondent commits:

$ git tag
osgeolive-6.5
v8.0
...

$ git show-ref --tags
e7e66977c1f34be5627a268adb4b9b3d59700e40 refs/tags/osgeolive-6.5
8f27e65bddd7d4b8515ce620fb485fdd78fcdf89 refs/tags/v8.0
...
Campa
  • 3,502
  • 3
  • 30
  • 34
  • 1
    Being used to Mercurial's `hg tags` I like that `git show-ref` gives me the tag AND the revision. – Justin Jan 08 '15 at 19:38
44

And here is how you find the remote tags:

git ls-remote --tags origin

Dimitri Dewaele
  • 9,061
  • 17
  • 67
  • 116
20

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

$ git tag
v5.5
v6.5

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

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

Getting latest tag on git repository

The command finds the most recent tag that is reachable from a commit. If the tag points to the commit, then only the tag is shown. Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit.

git describe

With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:

git describe --abbrev=0

Other examples:

git describe --abbrev=0 --tags # gets tag from current branch
git describe --tags `git rev-list --tags --max-count=1` // gets tags across all branches, not just the current branch

How to prune local git tags that don't exist on remote

To put it simple, if you are trying to do something like git fetch -p -t, it will not work starting with git version 1.9.4.

However, there is a simple workaround that still works in latest versions:

git tag -l | xargs git tag -d  // remove all local tags
git fetch -t                   // fetch remote tags
L Y E S - C H I O U K H
  • 3,827
  • 7
  • 32
  • 52
  • The *rev-list* related command gave me a list, but ended in an error: `v0.1.0-rc1 fatal: No tags can describe '5db7534...4a94'. Try --always, or create some tags.` – not2qubit Apr 08 '19 at 17:22
15

Try to make git tag it should be enough if not try to make git fetch then git tag.

toto
  • 345
  • 2
  • 10
  • 4
    I think what he means is this: Running `git tag` command should be enough if you just want to see a list of available tags. If you can't see some tags that you believe may exist on remote, then your local tags may not be in sync with remote. In this case, fetch the latest refs/heads from remote first `git fetch`, followed by the actual `git tag`. I usually run a one-liner like this: `$ git fetch -p && git tag`just to be sure I am looking at latest and greatest. – demisx May 29 '14 at 21:47
10

To see details about the latest available tag I sometimes use:

git show `git describe` --pretty=fuller
Andrei Sura
  • 1,669
  • 16
  • 14
6

If you want to check you tag name locally, you have to go to the path where you have created tag(local path). Means where you have put your objects. Then type command:

git show --name-only <tagname>

It will show all the objects under that tag name. I am working in Teradata and object means view, table etc

Léo Léopold Hertz 준영
  • 119,377
  • 159
  • 417
  • 655
Tanaya
  • 61
  • 1
  • 1
5

You can list all existing tags git tag or you could filter the list with git tag -l 'v1.1.*', where * acts as a wildcard. It will return a list of tags marked with v1.1.

You will notice that when you call git tag you do not get to see the contents of your annotations. To preview them you must add -n to your command: git tag -n2.

$ git tag -l -n2

v1.0 Release version 1.0

v1.1 Release version 1.1

The command lists all existing tags with maximum 3 lines of their tag message. By default -n only shows the first line. For more info be sure to check this tag related article as well.

Nesha Zoric
  • 4,618
  • 33
  • 33
0

For a GUI to do this I have just found that 'gitk' supports named views. The views have several options for selecting commits. One handy one is a box for selecting "All tags". That seems to work for me to see the tags.

O. B. J.
  • 11
  • 2