blob: 36e81b9dec45c08a19d5ef4d7840037923d02f8d [file] [log] [blame]
Jonas Fonsecac0990ff2006-09-18 14:32:41 +02001git-show-ref(1)
2===============
3
4NAME
5----
6git-show-ref - List references in a local repository
7
8SYNOPSIS
9--------
10[verse]
Ævar Arnfjörð Bjarmasone2f4e7e2022-10-13 17:39:06 +020011'git show-ref' [-q | --quiet] [--verify] [--head] [-d | --dereference]
12 [-s | --hash[=<n>]] [--abbrev[=<n>]] [--tags]
Holger Weiß4318d3b2010-03-29 13:02:37 +020013 [--heads] [--] [<pattern>...]
Junio C Hamano33e8fc82015-10-16 11:27:42 -070014'git show-ref' --exclude-existing[=<pattern>]
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020015
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
Doug Bell3f3d0ce2013-07-16 19:05:14 -050024By default, shows the tags, heads, and remote refs.
25
Sean Allred00bf6852023-05-19 04:17:49 +000026The `--exclude-existing` form is a filter that does the inverse. It reads
Junio C Hamano33e8fc82015-10-16 11:27:42 -070027refs from stdin, one ref per line, and shows those that don't exist in
28the local repository.
Julian Phillips8bd26c42007-04-09 21:57:36 +010029
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020030Use of this utility is encouraged in favor of directly accessing files under
Stephen Boydd4900ee2009-06-20 21:40:45 -070031the `.git` directory.
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020032
33OPTIONS
34-------
35
Stephan Beyer32402402008-06-08 03:36:09 +020036--head::
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020037
Doug Bell3f3d0ce2013-07-16 19:05:14 -050038 Show the HEAD reference, even if it would normally be filtered out.
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020039
Stephan Beyer32402402008-06-08 03:36:09 +020040--heads::
Elijah Newrenbd8d6f02019-01-09 11:58:47 -080041--tags::
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020042
Doug Bell3f3d0ce2013-07-16 19:05:14 -050043 Limit to "refs/heads" and "refs/tags", respectively. These options
44 are not mutually exclusive; when given both, references stored in
45 "refs/heads" and "refs/tags" are displayed.
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020046
Stephan Beyer32402402008-06-08 03:36:09 +020047-d::
48--dereference::
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020049
Martin Ågren18c4aac2023-08-16 16:24:35 +020050 Dereference tags into object IDs as well. They will be shown with `^{}`
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020051 appended.
52
Stephan Beyer32402402008-06-08 03:36:09 +020053-s::
Stephen Boyd69932bc2009-06-20 21:40:46 -070054--hash[=<n>]::
Christian Couder9581e0f2006-09-20 06:14:54 +020055
Sean Allred00bf6852023-05-19 04:17:49 +000056 Only show the OID, not the reference name. When combined with
57 `--dereference`, the dereferenced tag will still be shown after the OID.
Christian Couder9581e0f2006-09-20 06:14:54 +020058
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020059--verify::
60
61 Enable stricter reference checking by requiring an exact ref path.
62 Aside from returning an error code of 1, it will also print an error
Matthieu Moybcf96262016-06-28 13:40:11 +020063 message if `--quiet` was not specified.
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020064
Stephen Boyd69932bc2009-06-20 21:40:46 -070065--abbrev[=<n>]::
Junio C Hamano2eaf2222006-10-01 00:27:27 -070066
67 Abbreviate the object name. When using `--hash`, you do
Stephen Boyd69932bc2009-06-20 21:40:46 -070068 not have to say `--hash --abbrev`; `--hash=n` would do.
Junio C Hamano2eaf2222006-10-01 00:27:27 -070069
Stephan Beyer32402402008-06-08 03:36:09 +020070-q::
71--quiet::
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020072
Sean Allred00bf6852023-05-19 04:17:49 +000073 Do not print any results to stdout. When combined with `--verify`, this
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020074 can be used to silently check if a reference exists.
75
Stephen Boyd69932bc2009-06-20 21:40:46 -070076--exclude-existing[=<pattern>]::
Julian Phillips8bd26c42007-04-09 21:57:36 +010077
Sean Allred00bf6852023-05-19 04:17:49 +000078 Make `git show-ref` act as a filter that reads refs from stdin of the
79 form `^(?:<anything>\s)?<refname>(?:\^{})?$`
Jonathan Niederf1005982010-08-20 05:23:54 -050080 and performs the following actions on each:
Martin Ågren18c4aac2023-08-16 16:24:35 +020081 (1) strip `^{}` at the end of line if any;
Julian Phillips8bd26c42007-04-09 21:57:36 +010082 (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
Abhijit Menon-Senf448e242008-07-30 15:03:43 +053088<pattern>...::
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020089
Michael J Gruber9fbd8982010-10-18 13:33:32 +020090 Show references matching one or more patterns. Patterns are matched from
91 the end of the full name, and only complete parts are matched, e.g.
92 'master' matches 'refs/heads/master', 'refs/remotes/origin/master',
Justin Lebara58088a2014-03-31 15:11:44 -070093 'refs/tags/jedi/master' but not 'refs/heads/mymaster' or
Michael J Gruber9fbd8982010-10-18 13:33:32 +020094 'refs/remotes/master/jedi'.
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020095
96OUTPUT
97------
98
Sean Allred00bf6852023-05-19 04:17:49 +000099The output is in the format:
100
101------------
102<oid> SP <ref> LF
103------------
104
105For example,
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200106
107-----------------------------------------------------------------------------
108$ git show-ref --head --dereference
109832e76a9899f560a90ffd62ae2ce83bbeff58f54 HEAD
110832e76a9899f560a90ffd62ae2ce83bbeff58f54 refs/heads/master
111832e76a9899f560a90ffd62ae2ce83bbeff58f54 refs/heads/origin
1123521017556c5de4159da4615a39fa4d5d2c279b5 refs/tags/v0.99.9c
1136ddc0964034342519a87fe013781abf31c6db6ad refs/tags/v0.99.9c^{}
114055e4ae3ae6eb344cbabf2a5256a49ea66040131 refs/tags/v1.0rc4
115423325a2d24638ddcc82ce47be5e40be550f4507 refs/tags/v1.0rc4^{}
116...
117-----------------------------------------------------------------------------
118
Sean Allred00bf6852023-05-19 04:17:49 +0000119When using `--hash` (and not `--dereference`), the output is in the format:
120
121------------
122<oid> LF
123------------
124
125For example,
Christian Couder9581e0f2006-09-20 06:14:54 +0200126
127-----------------------------------------------------------------------------
128$ git show-ref --heads --hash
1292e3ba0114a1f52b47df29743d6915d056be13278
130185008ae97960c8d551adcd9e23565194651b5d1
13103adf42c988195b50e1a1935ba5fcbc39b2b029b
132...
133-----------------------------------------------------------------------------
134
Nguyễn Thái Ngọc Duy76a87882018-04-30 17:35:33 +0200135EXAMPLES
136--------
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200137
138To show all references called "master", whether tags or heads or anything
139else, and regardless of how deep in the reference naming hierarchy they are,
140use:
141
142-----------------------------------------------------------------------------
143 git show-ref master
144-----------------------------------------------------------------------------
145
146This will show "refs/heads/master" but also "refs/remote/other-repo/master",
Elijah Newrence14cc02023-10-08 06:45:09 +0000147if such references exist.
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200148
Matthieu Moybcf96262016-06-28 13:40:11 +0200149When using the `--verify` flag, the command requires an exact path:
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200150
151-----------------------------------------------------------------------------
152 git show-ref --verify refs/heads/master
153-----------------------------------------------------------------------------
154
155will only match the exact branch called "master".
156
Sean Allred00bf6852023-05-19 04:17:49 +0000157If nothing matches, `git show-ref` will return an error code of 1,
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200158and in the case of verification, it will show an error message.
159
Sean Allred00bf6852023-05-19 04:17:49 +0000160For scripting, you can ask it to be quiet with the `--quiet` flag, which
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200161allows you to do things like
162
163-----------------------------------------------------------------------------
Jonathan Niederb1889c32008-06-30 01:09:04 -0500164 git show-ref --quiet --verify -- "refs/heads/$headname" ||
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200165 echo "$headname is not a valid branch"
166-----------------------------------------------------------------------------
167
168to check whether a particular branch exists or not (notice how we don't
169actually want to show any results, and we want to use the full refname for it
170in order to not trigger the problem with ambiguous partial matches).
171
Sean Allred00bf6852023-05-19 04:17:49 +0000172To show only tags, or only proper branch heads, use `--tags` and/or `--heads`
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200173respectively (using both means that it shows tags and heads, but not other
174random references under the refs/ subdirectory).
175
Sean Allred00bf6852023-05-19 04:17:49 +0000176To do automatic tag object dereferencing, use the `-d` or `--dereference`
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200177flag, so you can do
178
179-----------------------------------------------------------------------------
180 git show-ref --tags --dereference
181-----------------------------------------------------------------------------
182
183to get a listing of all tags together with what they dereference.
184
Jonathan Nieder977ed832010-08-08 20:32:43 -0500185FILES
186-----
187`.git/refs/*`, `.git/packed-refs`
188
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200189SEE ALSO
190--------
Michael Haggertyf21e1c52014-01-22 12:23:20 +0100191linkgit:git-for-each-ref[1],
Jonathan Nieder977ed832010-08-08 20:32:43 -0500192linkgit:git-ls-remote[1],
193linkgit:git-update-ref[1],
194linkgit:gitrepository-layout[5]
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200195
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200196GIT
197---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200198Part of the linkgit:git[1] suite