You have essentially just two options, assuming only standard Git tools (if you have non-Git tools, especially ones you can program, you can of course do whatever you like). These two options are:
- Use
git fetch
as already described in ElpieKay's answer.
Sticking with git ls-remote
, note that git ls-remote
resolves tags1 for you:
$ git ls-remote origin
[snip]
aaa74e8c5b085572ee6bf3381167c1d428c8d685 refs/heads/pu
8bb94d66bf85d73f8866611161fb6022d68fdf13 refs/heads/todo
d5aef6e4d58cfe1549adef5b436f3ace984e8c86 refs/tags/gitgui-0.10.0
3d654be48f65545c4d3e35f5d3bbed5489820930 refs/tags/gitgui-0.10.0^{}
33682a5e98adfd8ba4ce0e21363c443bd273eb77 refs/tags/gitgui-0.10.1
729ffa50f75a025935623bfc58d0932c65f7de2f refs/tags/gitgui-0.10.1^{}
[snip]
If you save all of this output, you can scan through it for branch and tag names.
Branch names are simply references of the form refs/heads/*
: in this case the remote Git has branches pu
and todo
, for instance. Since branch names always point to commit IDs, the hashes to the left of these names are commit hashes.
Tag names are simply references of the form refs/tags/*
: in this case, the tag list begins with numerous gitgui-*
tags. Each of these is an annotated tag, so git ls-remote
shows not only the tag object ID such as d5aef6e4d58cfe1549adef5b436f3ace984e8c86
, but also that tag object's target, 3d654be48f65545c4d3e35f5d3bbed5489820930
. This is the second line of output, showing refs/tags/gitgui-0.10.0^{}
, which is gitrevisions
syntax:
A suffix ^ followed by an empty brace pair means the object could be a tag, and dereference the tag recursively until a non-tag object is found.
Note that if you do wish to "re-fetch" tags via git fetch
, you can tell your Git to force-update your tags, or force-update the other Git's tags into a private namespace of your own ("remote tags", if you will: see Git - Checkout a remote tag when two remotes have the same tag name). To make Git force-update your current tags, add +refs/tags/*:refs/tags/*
to your fetch refspecs (either on the command line, or in a fetch =
configuration entry). Overwriting your current tags does, of course, have the obvious drawback that you no longer have the old tags.