82

Anyone know how to check if a tag is on the git remote after the tag is pushed from the local?

It seems that the only way to do it is to fetch the remote.

lcb
  • 999
  • 1
  • 6
  • 10

4 Answers4

113

Try

git ls-remote --tags origin
Abe Voelker
  • 30,124
  • 14
  • 81
  • 98
  • 10
    thanks, it works perfectly. But I till have another question. I got these results: refs/tags/0.1, refs/tags/0.1^{}. Do you know what is the second one? – lcb Jun 09 '11 at 16:04
  • Sounds like a separate question entirely. – RyPeck Jul 03 '13 at 18:34
  • 1
    @lcb This doesn't answer your question, but if you can add the tag name after origin and it will only list a tag that matches exactly. – Mark Evans Sep 29 '13 at 01:37
  • 1
    @lcb the answer to "why the duplicate tags" is addressed here: http://stackoverflow.com/questions/5346060/git-tag-why-this-duplicate-tag-in-remotes – bryanbraun Dec 21 '13 at 17:39
  • 14
    Pass `--exit-code` to `ls-remote` if you want a non-zero status when no tag found, e.g. `git ls-remote --exit-code --tags origin v1.2.3`. – Paul Annesley Mar 14 '14 at 00:35
43

To more precisely answer this question, to check if a specific tag is in a given remote use:

git ls-remote <remote-name> refs/tags/<tag-name>
Diego
  • 5,326
  • 1
  • 35
  • 32
  • 4
    How do I verify that it’s the same tag as local (i.e., that it points to the same commit)? – binki May 22 '18 at 04:37
  • 9
    If you are wanting to perform this check in a script, for example during a CI process, you can pass the `--exit-code` option: `git ls-remote --exit-code refs/tags/` It will return an exit code of 0 if the tag is in the remote, an exit code of 2 if Git was able to connect to the remote but the tag was NOT present, and presumably an exit code of 1 if it was unable to connect to the remote. You can then check the exit code and perform your logic based on the result. – Joe Alamo Apr 12 '19 at 13:55
7

For lazy people like me, I used to search for it like this:

On remote tags:

git ls-remote --tags origin | grep TAG_NAME

On local tags.

git tag -l  | grep TAG_NAME
HMagdy
  • 3,029
  • 33
  • 54
-3

Another way, (from "git: check if commit xyz in remote repo?")

git branch -r --contains my_tag

# ==== or with a sha1: =====
git branch -r --contains 2e29022d

This will list the remote branches that contain the tag or commit.

The output will look like:

origin/my_branch_1
origin/my_other_branch
origin/master
Community
  • 1
  • 1
dgo.a
  • 2,634
  • 23
  • 35
  • 2
    This shows that the commit the tag references is on the remote. It does not test whether the actual tag was pushed to the remote. – Mark Evans Sep 29 '13 at 01:29