blob: d1d56f68b4376279534d61ec44db10e9e6efd297 [file] [log] [blame]
Junio C Hamanoa2ec14f2006-11-02 00:22:481git-show-ref(1)
2===============
3
4NAME
5----
6git-show-ref - List references in a local repository
7
8SYNOPSIS
9--------
10[verse]
Junio C Hamanocf9c7732022-10-28 18:56:0611'git show-ref' [-q | --quiet] [--verify] [--head] [-d | --dereference]
12 [-s | --hash[=<n>]] [--abbrev[=<n>]] [--tags]
Junio C Hamano1f630d52010-04-01 04:49:2513 [--heads] [--] [<pattern>...]
Junio C Hamanodaf0aae2015-10-26 23:14:3014'git show-ref' --exclude-existing[=<pattern>]
Junio C Hamanoa2ec14f2006-11-02 00:22:4815
16DESCRIPTION
17-----------
18
19Displays references available in a local repository along with the associated
20commit IDs. Results can be filtered using a pattern and tags can be
21dereferenced into object IDs. Additionally, it can be used to test whether a
22particular ref exists.
23
Junio C Hamano58f587a2013-07-22 19:20:5924By default, shows the tags, heads, and remote refs.
25
Junio C Hamanodaf0aae2015-10-26 23:14:3026The --exclude-existing form is a filter that does the inverse. It reads
27refs from stdin, one ref per line, and shows those that don't exist in
28the local repository.
Junio C Hamanoc3f1dbf2007-04-10 21:31:3229
Junio C Hamanoa2ec14f2006-11-02 00:22:4830Use of this utility is encouraged in favor of directly accessing files under
Junio C Hamano0e88f3e2009-06-21 08:03:2531the `.git` directory.
Junio C Hamanoa2ec14f2006-11-02 00:22:4832
33OPTIONS
34-------
35
Junio C Hamanoeb415992008-06-08 22:49:4736--head::
Junio C Hamanoa2ec14f2006-11-02 00:22:4837
Junio C Hamano58f587a2013-07-22 19:20:5938Show the HEAD reference, even if it would normally be filtered out.
Junio C Hamanoa2ec14f2006-11-02 00:22:4839
Junio C Hamanoeb415992008-06-08 22:49:4740--heads::
Junio C Hamanoace33e42019-01-18 23:16:0541--tags::
Junio C Hamanoa2ec14f2006-11-02 00:22:4842
Junio C Hamano58f587a2013-07-22 19:20:5943Limit to "refs/heads" and "refs/tags", respectively. These options
44are not mutually exclusive; when given both, references stored in
45"refs/heads" and "refs/tags" are displayed.
Junio C Hamanoa2ec14f2006-11-02 00:22:4846
Junio C Hamanoeb415992008-06-08 22:49:4747-d::
48--dereference::
Junio C Hamanoa2ec14f2006-11-02 00:22:4849
Junio C Hamanobfeab4e2012-01-19 00:51:2750Dereference tags into object IDs as well. They will be shown with "{caret}{}"
Junio C Hamanoa2ec14f2006-11-02 00:22:4851appended.
52
Junio C Hamanoeb415992008-06-08 22:49:4753-s::
Junio C Hamanoccc4d372009-07-06 18:05:3854--hash[=<n>]::
Junio C Hamanoa2ec14f2006-11-02 00:22:4855
Junio C Hamanoe3f080d2013-04-22 02:27:1356Only show the SHA-1 hash, not the reference name. When combined with
57--dereference the dereferenced tag will still be shown after the SHA-1.
Junio C Hamanoa2ec14f2006-11-02 00:22:4858
59--verify::
60
61Enable stricter reference checking by requiring an exact ref path.
62Aside from returning an error code of 1, it will also print an error
Junio C Hamano92d80372016-07-13 22:00:0563message if `--quiet` was not specified.
Junio C Hamanoa2ec14f2006-11-02 00:22:4864
Junio C Hamanoccc4d372009-07-06 18:05:3865--abbrev[=<n>]::
Junio C Hamanoa2ec14f2006-11-02 00:22:4866
67Abbreviate the object name. When using `--hash`, you do
Junio C Hamanoccc4d372009-07-06 18:05:3868not have to say `--hash --abbrev`; `--hash=n` would do.
Junio C Hamanoa2ec14f2006-11-02 00:22:4869
Junio C Hamanoeb415992008-06-08 22:49:4770-q::
71--quiet::
Junio C Hamanoa2ec14f2006-11-02 00:22:4872
Junio C Hamano92d80372016-07-13 22:00:0573Do not print any results to stdout. When combined with `--verify` this
Junio C Hamanoa2ec14f2006-11-02 00:22:4874can be used to silently check if a reference exists.
75
Junio C Hamanoccc4d372009-07-06 18:05:3876--exclude-existing[=<pattern>]::
Junio C Hamanoc3f1dbf2007-04-10 21:31:3277
Junio C Hamano1aa40d22010-01-21 17:46:4378Make 'git show-ref' act as a filter that reads refs from stdin of the
Junio C Hamanob76a6862012-05-02 22:02:4679form "`^(?:<anything>\s)?<refname>(?:\^{})?$`"
Junio C Hamano2db3e752010-09-03 21:33:0680and performs the following actions on each:
Junio C Hamanobfeab4e2012-01-19 00:51:2781(1) strip "{caret}{}" at the end of line if any;
Junio C Hamanoc3f1dbf2007-04-10 21:31:3282(2) ignore if pattern is provided and does not head-match refname;
83(3) warn if refname is not a well-formed refname and skip;
84(4) ignore if refname is a ref that exists in the local repository;
85(5) otherwise output the line.
86
87
Junio C Hamano9e395072008-07-31 22:11:2188<pattern>...::
Junio C Hamanoa2ec14f2006-11-02 00:22:4889
Junio C Hamano7f9fa862010-10-19 23:51:1490Show references matching one or more patterns. Patterns are matched from
91the end of the full name, and only complete parts are matched, e.g.
92'master' matches 'refs/heads/master', 'refs/remotes/origin/master',
Junio C Hamanod75148a2014-04-08 19:48:3893'refs/tags/jedi/master' but not 'refs/heads/mymaster' or
Junio C Hamano7f9fa862010-10-19 23:51:1494'refs/remotes/master/jedi'.
Junio C Hamanoa2ec14f2006-11-02 00:22:4895
96OUTPUT
97------
98
99The output is in the format: '<SHA-1 ID>' '<space>' '<reference name>'.
100
101-----------------------------------------------------------------------------
102$ git show-ref --head --dereference
103832e76a9899f560a90ffd62ae2ce83bbeff58f54 HEAD
104832e76a9899f560a90ffd62ae2ce83bbeff58f54 refs/heads/master
105832e76a9899f560a90ffd62ae2ce83bbeff58f54 refs/heads/origin
1063521017556c5de4159da4615a39fa4d5d2c279b5 refs/tags/v0.99.9c
1076ddc0964034342519a87fe013781abf31c6db6ad refs/tags/v0.99.9c^{}
108055e4ae3ae6eb344cbabf2a5256a49ea66040131 refs/tags/v1.0rc4
109423325a2d24638ddcc82ce47be5e40be550f4507 refs/tags/v1.0rc4^{}
110...
111-----------------------------------------------------------------------------
112
113When using --hash (and not --dereference) the output format is: '<SHA-1 ID>'
114
115-----------------------------------------------------------------------------
116$ git show-ref --heads --hash
1172e3ba0114a1f52b47df29743d6915d056be13278
118185008ae97960c8d551adcd9e23565194651b5d1
11903adf42c988195b50e1a1935ba5fcbc39b2b029b
120...
121-----------------------------------------------------------------------------
122
Junio C Hamanob9d9d902018-05-23 07:07:42123EXAMPLES
124--------
Junio C Hamanoa2ec14f2006-11-02 00:22:48125
126To show all references called "master", whether tags or heads or anything
127else, and regardless of how deep in the reference naming hierarchy they are,
128use:
129
130-----------------------------------------------------------------------------
131git show-ref master
132-----------------------------------------------------------------------------
133
134This will show "refs/heads/master" but also "refs/remote/other-repo/master",
135if such references exists.
136
Junio C Hamano92d80372016-07-13 22:00:05137When using the `--verify` flag, the command requires an exact path:
Junio C Hamanoa2ec14f2006-11-02 00:22:48138
139-----------------------------------------------------------------------------
140git show-ref --verify refs/heads/master
141-----------------------------------------------------------------------------
142
143will only match the exact branch called "master".
144
Junio C Hamano1aa40d22010-01-21 17:46:43145If nothing matches, 'git show-ref' will return an error code of 1,
Junio C Hamanoa2ec14f2006-11-02 00:22:48146and in the case of verification, it will show an error message.
147
148For scripting, you can ask it to be quiet with the "--quiet" flag, which
149allows you to do things like
150
151-----------------------------------------------------------------------------
Junio C Hamanofce7c7e2008-07-02 03:06:38152git show-ref --quiet --verify -- "refs/heads/$headname" ||
Junio C Hamanoa2ec14f2006-11-02 00:22:48153echo "$headname is not a valid branch"
154-----------------------------------------------------------------------------
155
156to check whether a particular branch exists or not (notice how we don't
157actually want to show any results, and we want to use the full refname for it
158in order to not trigger the problem with ambiguous partial matches).
159
160To show only tags, or only proper branch heads, use "--tags" and/or "--heads"
161respectively (using both means that it shows tags and heads, but not other
162random references under the refs/ subdirectory).
163
164To do automatic tag object dereferencing, use the "-d" or "--dereference"
165flag, so you can do
166
167-----------------------------------------------------------------------------
168git show-ref --tags --dereference
169-----------------------------------------------------------------------------
170
171to get a listing of all tags together with what they dereference.
172
Junio C Hamanoe85e36f2010-08-10 05:30:14173FILES
174-----
175`.git/refs/*`, `.git/packed-refs`
176
Junio C Hamanoa2ec14f2006-11-02 00:22:48177SEE ALSO
178--------
Junio C Hamanofd98be82014-01-22 22:45:38179linkgit:git-for-each-ref[1],
Junio C Hamanoe85e36f2010-08-10 05:30:14180linkgit:git-ls-remote[1],
181linkgit:git-update-ref[1],
182linkgit:gitrepository-layout[5]
Junio C Hamanoa2ec14f2006-11-02 00:22:48183
Junio C Hamanoa2ec14f2006-11-02 00:22:48184GIT
185---
Junio C Hamanof7c042d2008-06-06 22:50:53186Part of the linkgit:git[1] suite