blob: fcee0008a9d868bb27c9eacbcfe72a3a3f8ed60f [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]
Jonathan Niedere62b3932009-11-09 09:04:46 -060011'git show-ref' [-q|--quiet] [--verify] [--head] [-d|--dereference]
Stephen Boyd69932bc2009-06-20 21:40:46 -070012 [-s|--hash[=<n>]] [--abbrev[=<n>]] [--tags]
Holger Weiß4318d3b2010-03-29 13:02:37 +020013 [--heads] [--] [<pattern>...]
Stephen Boyd69932bc2009-06-20 21:40:46 -070014'git show-ref' --exclude-existing[=<pattern>] < ref-list
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
Julian Phillips8bd26c42007-04-09 21:57:36 +010024The --exclude-existing form is a filter that does the inverse, it shows the
25refs from stdin that don't exist in the local repository.
26
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020027Use of this utility is encouraged in favor of directly accessing files under
Stephen Boydd4900ee2009-06-20 21:40:45 -070028the `.git` directory.
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020029
30OPTIONS
31-------
32
Stephan Beyer32402402008-06-08 03:36:09 +020033--head::
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020034
35 Show the HEAD reference.
36
Stephan Beyer32402402008-06-08 03:36:09 +020037--tags::
38--heads::
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020039
40 Limit to only "refs/heads" and "refs/tags", respectively. These
41 options are not mutually exclusive; when given both, references stored
42 in "refs/heads" and "refs/tags" are displayed.
43
Stephan Beyer32402402008-06-08 03:36:09 +020044-d::
45--dereference::
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020046
Michael Haggerty6ab26082012-01-13 17:39:15 +010047 Dereference tags into object IDs as well. They will be shown with "{caret}{}"
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020048 appended.
49
Stephan Beyer32402402008-06-08 03:36:09 +020050-s::
Stephen Boyd69932bc2009-06-20 21:40:46 -070051--hash[=<n>]::
Christian Couder9581e0f2006-09-20 06:14:54 +020052
Stephen Boydd4900ee2009-06-20 21:40:45 -070053 Only show the SHA1 hash, not the reference name. When combined with
Junio C Hamano2eaf2222006-10-01 00:27:27 -070054 --dereference the dereferenced tag will still be shown after the SHA1.
Christian Couder9581e0f2006-09-20 06:14:54 +020055
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020056--verify::
57
58 Enable stricter reference checking by requiring an exact ref path.
59 Aside from returning an error code of 1, it will also print an error
60 message if '--quiet' was not specified.
61
Stephen Boyd69932bc2009-06-20 21:40:46 -070062--abbrev[=<n>]::
Junio C Hamano2eaf2222006-10-01 00:27:27 -070063
64 Abbreviate the object name. When using `--hash`, you do
Stephen Boyd69932bc2009-06-20 21:40:46 -070065 not have to say `--hash --abbrev`; `--hash=n` would do.
Junio C Hamano2eaf2222006-10-01 00:27:27 -070066
Stephan Beyer32402402008-06-08 03:36:09 +020067-q::
68--quiet::
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020069
70 Do not print any results to stdout. When combined with '--verify' this
71 can be used to silently check if a reference exists.
72
Stephen Boyd69932bc2009-06-20 21:40:46 -070073--exclude-existing[=<pattern>]::
Julian Phillips8bd26c42007-04-09 21:57:36 +010074
Thomas Rast0b444cd2010-01-10 00:33:00 +010075 Make 'git show-ref' act as a filter that reads refs from stdin of the
Michael Haggerty87b340b2012-01-13 17:39:16 +010076 form "`{caret}(?:<anything>\s)?<refname>(?:{backslash}{caret}{})?$`"
Jonathan Niederf1005982010-08-20 05:23:54 -050077 and performs the following actions on each:
Michael Haggerty6ab26082012-01-13 17:39:15 +010078 (1) strip "{caret}{}" at the end of line if any;
Julian Phillips8bd26c42007-04-09 21:57:36 +010079 (2) ignore if pattern is provided and does not head-match refname;
80 (3) warn if refname is not a well-formed refname and skip;
81 (4) ignore if refname is a ref that exists in the local repository;
82 (5) otherwise output the line.
83
84
Abhijit Menon-Senf448e242008-07-30 15:03:43 +053085<pattern>...::
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020086
Michael J Gruber9fbd8982010-10-18 13:33:32 +020087 Show references matching one or more patterns. Patterns are matched from
88 the end of the full name, and only complete parts are matched, e.g.
89 'master' matches 'refs/heads/master', 'refs/remotes/origin/master',
90 'refs/tags/jedi/master' but not 'refs/heads/mymaster' nor
91 'refs/remotes/master/jedi'.
Jonas Fonsecac0990ff2006-09-18 14:32:41 +020092
93OUTPUT
94------
95
96The output is in the format: '<SHA-1 ID>' '<space>' '<reference name>'.
97
98-----------------------------------------------------------------------------
99$ git show-ref --head --dereference
100832e76a9899f560a90ffd62ae2ce83bbeff58f54 HEAD
101832e76a9899f560a90ffd62ae2ce83bbeff58f54 refs/heads/master
102832e76a9899f560a90ffd62ae2ce83bbeff58f54 refs/heads/origin
1033521017556c5de4159da4615a39fa4d5d2c279b5 refs/tags/v0.99.9c
1046ddc0964034342519a87fe013781abf31c6db6ad refs/tags/v0.99.9c^{}
105055e4ae3ae6eb344cbabf2a5256a49ea66040131 refs/tags/v1.0rc4
106423325a2d24638ddcc82ce47be5e40be550f4507 refs/tags/v1.0rc4^{}
107...
108-----------------------------------------------------------------------------
109
Christian Couder9581e0f2006-09-20 06:14:54 +0200110When using --hash (and not --dereference) the output format is: '<SHA-1 ID>'
111
112-----------------------------------------------------------------------------
113$ git show-ref --heads --hash
1142e3ba0114a1f52b47df29743d6915d056be13278
115185008ae97960c8d551adcd9e23565194651b5d1
11603adf42c988195b50e1a1935ba5fcbc39b2b029b
117...
118-----------------------------------------------------------------------------
119
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200120EXAMPLE
121-------
122
123To show all references called "master", whether tags or heads or anything
124else, and regardless of how deep in the reference naming hierarchy they are,
125use:
126
127-----------------------------------------------------------------------------
128 git show-ref master
129-----------------------------------------------------------------------------
130
131This will show "refs/heads/master" but also "refs/remote/other-repo/master",
132if such references exists.
133
134When using the '--verify' flag, the command requires an exact path:
135
136-----------------------------------------------------------------------------
137 git show-ref --verify refs/heads/master
138-----------------------------------------------------------------------------
139
140will only match the exact branch called "master".
141
Thomas Rast0b444cd2010-01-10 00:33:00 +0100142If nothing matches, 'git show-ref' will return an error code of 1,
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200143and in the case of verification, it will show an error message.
144
145For scripting, you can ask it to be quiet with the "--quiet" flag, which
146allows you to do things like
147
148-----------------------------------------------------------------------------
Jonathan Niederb1889c32008-06-30 01:09:04 -0500149 git show-ref --quiet --verify -- "refs/heads/$headname" ||
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200150 echo "$headname is not a valid branch"
151-----------------------------------------------------------------------------
152
153to check whether a particular branch exists or not (notice how we don't
154actually want to show any results, and we want to use the full refname for it
155in order to not trigger the problem with ambiguous partial matches).
156
157To show only tags, or only proper branch heads, use "--tags" and/or "--heads"
158respectively (using both means that it shows tags and heads, but not other
159random references under the refs/ subdirectory).
160
161To do automatic tag object dereferencing, use the "-d" or "--dereference"
162flag, so you can do
163
164-----------------------------------------------------------------------------
165 git show-ref --tags --dereference
166-----------------------------------------------------------------------------
167
168to get a listing of all tags together with what they dereference.
169
Jonathan Nieder977ed832010-08-08 20:32:43 -0500170FILES
171-----
172`.git/refs/*`, `.git/packed-refs`
173
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200174SEE ALSO
175--------
Jonathan Nieder977ed832010-08-08 20:32:43 -0500176linkgit:git-ls-remote[1],
177linkgit:git-update-ref[1],
178linkgit:gitrepository-layout[5]
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200179
Jonas Fonsecac0990ff2006-09-18 14:32:41 +0200180GIT
181---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200182Part of the linkgit:git[1] suite