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