1GIT-SHOW-REF(1) Git Manual GIT-SHOW-REF(1)
2
3
4
6 git-show-ref - List references in a local repository
7
9 git show-ref [--head] [-d | --dereference]
10 [-s | --hash[=<n>]] [--abbrev[=<n>]] [--tags]
11 [--heads] [--] [<pattern>...]
12 git show-ref --verify [-q | --quiet] [-d | --dereference]
13 [-s | --hash[=<n>]] [--abbrev[=<n>]]
14 [--] [<ref>...]
15 git show-ref --exclude-existing[=<pattern>]
16 git show-ref --exists <ref>
17
19 Displays references available in a local repository along with the
20 associated commit IDs. Results can be filtered using a pattern and tags
21 can be dereferenced into object IDs. Additionally, it can be used to
22 test whether a particular ref exists.
23
24 By default, shows the tags, heads, and remote refs.
25
26 The --exclude-existing form is a filter that does the inverse. It reads
27 refs from stdin, one ref per line, and shows those that don’t exist in
28 the local repository.
29
30 The --exists form can be used to check for the existence of a single
31 references. This form does not verify whether the reference resolves to
32 an actual object.
33
34 Use of this utility is encouraged in favor of directly accessing files
35 under the .git directory.
36
38 --head
39 Show the HEAD reference, even if it would normally be filtered out.
40
41 --heads, --tags
42 Limit to "refs/heads" and "refs/tags", respectively. These options
43 are not mutually exclusive; when given both, references stored in
44 "refs/heads" and "refs/tags" are displayed.
45
46 -d, --dereference
47 Dereference tags into object IDs as well. They will be shown with
48 ^{} appended.
49
50 -s, --hash[=<n>]
51 Only show the OID, not the reference name. When combined with
52 --dereference, the dereferenced tag will still be shown after the
53 OID.
54
55 --verify
56 Enable stricter reference checking by requiring an exact ref path.
57 Aside from returning an error code of 1, it will also print an
58 error message if --quiet was not specified.
59
60 --exists
61 Check whether the given reference exists. Returns an exit code of 0
62 if it does, 2 if it is missing, and 1 in case looking up the
63 reference failed with an error other than the reference being
64 missing.
65
66 --abbrev[=<n>]
67 Abbreviate the object name. When using --hash, you do not have to
68 say --hash --abbrev; --hash=n would do.
69
70 -q, --quiet
71 Do not print any results to stdout. Can be used with --verify to
72 silently check if a reference exists.
73
74 --exclude-existing[=<pattern>]
75 Make git show-ref act as a filter that reads refs from stdin of the
76 form ^(?:<anything>\s)?<refname>(?:\^{})?$ and performs the
77 following actions on each: (1) strip ^{} at the end of line if any;
78 (2) ignore if pattern is provided and does not head-match refname;
79 (3) warn if refname is not a well-formed refname and skip; (4)
80 ignore if refname is a ref that exists in the local repository; (5)
81 otherwise output the line.
82
83 <pattern>...
84 Show references matching one or more patterns. Patterns are matched
85 from the end of the full name, and only complete parts are matched,
86 e.g. master matches refs/heads/master, refs/remotes/origin/master,
87 refs/tags/jedi/master but not refs/heads/mymaster or
88 refs/remotes/master/jedi.
89
91 The output is in the format:
92
93 <oid> SP <ref> LF
94
95 For example,
96
97 $ git show-ref --head --dereference
98 832e76a9899f560a90ffd62ae2ce83bbeff58f54 HEAD
99 832e76a9899f560a90ffd62ae2ce83bbeff58f54 refs/heads/master
100 832e76a9899f560a90ffd62ae2ce83bbeff58f54 refs/heads/origin
101 3521017556c5de4159da4615a39fa4d5d2c279b5 refs/tags/v0.99.9c
102 6ddc0964034342519a87fe013781abf31c6db6ad refs/tags/v0.99.9c^{}
103 055e4ae3ae6eb344cbabf2a5256a49ea66040131 refs/tags/v1.0rc4
104 423325a2d24638ddcc82ce47be5e40be550f4507 refs/tags/v1.0rc4^{}
105 ...
106
107 When using --hash (and not --dereference), the output is in the format:
108
109 <oid> LF
110
111 For example,
112
113 $ git show-ref --heads --hash
114 2e3ba0114a1f52b47df29743d6915d056be13278
115 185008ae97960c8d551adcd9e23565194651b5d1
116 03adf42c988195b50e1a1935ba5fcbc39b2b029b
117 ...
118
120 To show all references called "master", whether tags or heads or
121 anything else, and regardless of how deep in the reference naming
122 hierarchy they are, use:
123
124 git show-ref master
125
126 This will show "refs/heads/master" but also
127 "refs/remote/other-repo/master", if such references exist.
128
129 When using the --verify flag, the command requires an exact path:
130
131 git show-ref --verify refs/heads/master
132
133 will only match the exact branch called "master".
134
135 If nothing matches, git show-ref will return an error code of 1, and in
136 the case of verification, it will show an error message.
137
138 For scripting, you can ask it to be quiet with the --quiet flag, which
139 allows you to do things like
140
141 git show-ref --quiet --verify -- "refs/heads/$headname" ||
142 echo "$headname is not a valid branch"
143
144 to check whether a particular branch exists or not (notice how we don’t
145 actually want to show any results, and we want to use the full refname
146 for it in order to not trigger the problem with ambiguous partial
147 matches).
148
149 To show only tags, or only proper branch heads, use --tags and/or
150 --heads respectively (using both means that it shows tags and heads,
151 but not other random references under the refs/ subdirectory).
152
153 To do automatic tag object dereferencing, use the -d or --dereference
154 flag, so you can do
155
156 git show-ref --tags --dereference
157
158 to get a listing of all tags together with what they dereference.
159
161 .git/refs/*, .git/packed-refs
162
164 git-for-each-ref(1), git-ls-remote(1), git-update-ref(1),
165 gitrepository-layout(5)
166
168 Part of the git(1) suite
169
170
171
172Git 2.43.0 11/20/2023 GIT-SHOW-REF(1)