1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE sect2 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
\r
4 <sect2 lang="en" id="git-check-ref-format(1)">
\r
5 <title>git-check-ref-format(1)</title>
\r
7 <primary>git-check-ref-format(1)</primary>
\r
9 <simplesect id="git-check-ref-format(1)__name">
\r
11 <simpara>git-check-ref-format - Ensures that a reference name is well formed</simpara>
\r
13 <simplesect id="git-check-ref-format(1)__synopsis">
\r
14 <title>SYNOPSIS</title>
\r
16 <literallayout><emphasis>git check-ref-format</emphasis> [--normalize]
\r
17 [--[no-]allow-onelevel] [--refspec-pattern]
\r
19 <emphasis>git check-ref-format</emphasis> --branch <branchname-shorthand></literallayout>
\r
22 <simplesect id="git-check-ref-format(1)__description">
\r
23 <title>DESCRIPTION</title>
\r
24 <simpara>Checks if a given <emphasis>refname</emphasis> is acceptable, and exits with a non-zero
\r
25 status if it is not.</simpara>
\r
26 <simpara>A reference is used in Git to specify branches and tags. A
\r
27 branch head is stored in the <emphasis>refs/heads</emphasis> hierarchy, while
\r
28 a tag is stored in the <emphasis>refs/tags</emphasis> hierarchy of the ref namespace
\r
29 (typically in <emphasis>$GIT_DIR/refs/heads</emphasis> and <emphasis>$GIT_DIR/refs/tags</emphasis>
\r
30 directories or, as entries in file <emphasis>$GIT_DIR/packed-refs</emphasis>
\r
31 if refs are packed by <emphasis>git gc</emphasis>).</simpara>
\r
32 <simpara>Git imposes the following rules on how references are named:</simpara>
\r
33 <orderedlist numeration="arabic">
\r
36 They can include slash <emphasis>/</emphasis> for hierarchical (directory)
\r
37 grouping, but no slash-separated component can begin with a
\r
38 dot <emphasis>.</emphasis> or end with the sequence <emphasis>.lock</emphasis>.
\r
43 They must contain at least one <emphasis>/</emphasis>. This enforces the presence of a
\r
44 category like <emphasis>heads/</emphasis>, <emphasis>tags/</emphasis> etc. but the actual names are not
\r
45 restricted. If the <emphasis>--allow-onelevel</emphasis> option is used, this rule
\r
51 They cannot have two consecutive dots <emphasis>..</emphasis> anywhere.
\r
56 They cannot have ASCII control characters (i.e. bytes whose
\r
57 values are lower than \040, or \177 <emphasis>DEL</emphasis>), space, tilde <emphasis>~</emphasis>,
\r
58 caret <emphasis>^</emphasis>, or colon <emphasis>:</emphasis> anywhere.
\r
63 They cannot have question-mark <emphasis>?</emphasis>, asterisk <emphasis>*</emphasis>, or open
\r
64 bracket <emphasis>[</emphasis> anywhere. See the <emphasis>--refspec-pattern</emphasis> option below for
\r
65 an exception to this rule.
\r
70 They cannot begin or end with a slash <emphasis>/</emphasis> or contain multiple
\r
71 consecutive slashes (see the <emphasis>--normalize</emphasis> option below for an
\r
72 exception to this rule)
\r
77 They cannot end with a dot <emphasis>.</emphasis>.
\r
82 They cannot contain a sequence <emphasis>@{</emphasis>.
\r
87 They cannot be the single character <emphasis>@</emphasis>.
\r
92 They cannot contain a <emphasis>\</emphasis>.
\r
96 <simpara>These rules make it easy for shell script based tools to parse
\r
97 reference names, pathname expansion by the shell when a reference name is used
\r
98 unquoted (by mistake), and also avoid ambiguities in certain
\r
99 reference name expressions (see <xref linkend="gitrevisions(7)" />):</simpara>
\r
100 <orderedlist numeration="arabic">
\r
103 A double-dot <emphasis>..</emphasis> is often used as in <emphasis>ref1..ref2</emphasis>, and in some
\r
104 contexts this notation means <emphasis>^ref1 ref2</emphasis> (i.e. not in
\r
105 <emphasis>ref1</emphasis> and in <emphasis>ref2</emphasis>).
\r
110 A tilde <emphasis>~</emphasis> and caret <emphasis>^</emphasis> are used to introduce the postfix
\r
111 <emphasis>nth parent</emphasis> and <emphasis>peel onion</emphasis> operation.
\r
116 A colon <emphasis>:</emphasis> is used as in <emphasis>srcref:dstref</emphasis> to mean "use srcref's
\r
117 value and store it in dstref" in fetch and push operations.
\r
118 It may also be used to select a specific object such as with
\r
119 <emphasis>git cat-file</emphasis>: "git cat-file blob v1.3.3:refs.c".
\r
124 at-open-brace <emphasis>@{</emphasis> is used as a notation to access a reflog entry.
\r
128 <simpara>With the <emphasis>--branch</emphasis> option, it expands the previous branch syntax
\r
129 <emphasis>@{-n}</emphasis>. For example, <emphasis>@{-1}</emphasis> is a way to refer the last branch you
\r
130 were on. This option should be used by porcelains to accept this
\r
131 syntax anywhere a branch name is expected, so they can act as if you
\r
132 typed the branch name.</simpara>
\r
134 <simplesect id="git-check-ref-format(1)__options">
\r
135 <title>OPTIONS</title>
\r
139 --[no-]allow-onelevel
\r
143 Controls whether one-level refnames are accepted (i.e.,
\r
144 refnames that do not contain multiple <emphasis>/</emphasis>-separated
\r
145 components). The default is <emphasis>--no-allow-onelevel</emphasis>.
\r
155 Interpret <refname> as a reference name pattern for a refspec
\r
156 (as used with remote repositories). If this option is
\r
157 enabled, <refname> is allowed to contain a single <emphasis>*</emphasis>
\r
158 in the refspec (e.g., <emphasis>foo/bar*/baz</emphasis> or <emphasis>foo/bar*baz/</emphasis>
\r
159 but not <emphasis>foo/bar*/baz*</emphasis>).
\r
169 Normalize <emphasis>refname</emphasis> by removing any leading slash (<emphasis>/</emphasis>)
\r
170 characters and collapsing runs of adjacent slashes between
\r
171 name components into a single slash. Iff the normalized
\r
172 refname is valid then print it to standard output and exit
\r
173 with a status of 0. (<emphasis>--print</emphasis> is a deprecated way to spell
\r
174 <emphasis>--normalize</emphasis>.)
\r
180 <simplesect id="git-check-ref-format(1)__examples">
\r
181 <title>EXAMPLES</title>
\r
185 Print the name of the previous branch:
\r
187 <screen>$ git check-ref-format --branch @{-1}</screen>
\r
191 Determine the reference name to use for a new branch:
\r
193 <screen>$ ref=$(git check-ref-format --normalize "refs/heads/$newbranch") ||
\r
194 die "we do not like '$newbranch' as a branch name."</screen>
\r
198 <simplesect id="git-check-ref-format(1)__git">
\r
200 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r