1GIT-CHECK-REF-FOR(1)              Git Manual              GIT-CHECK-REF-FOR(1)
2
3
4

NAME

6       git-check-ref-format - Ensures that a reference name is well formed
7

SYNOPSIS

9       git check-ref-format [--normalize]
10              [--[no-]allow-onelevel] [--refspec-pattern]
11              <refname>
12       git check-ref-format --branch <branchname-shorthand>
13
14

DESCRIPTION

16       Checks if a given refname is acceptable, and exits with a non-zero
17       status if it is not.
18
19       A reference is used in Git to specify branches and tags. A branch head
20       is stored in the refs/heads hierarchy, while a tag is stored in the
21       refs/tags hierarchy of the ref namespace (typically in
22       $GIT_DIR/refs/heads and $GIT_DIR/refs/tags directories or, as entries
23       in file $GIT_DIR/packed-refs if refs are packed by git gc).
24
25       Git imposes the following rules on how references are named:
26
27        1. They can include slash / for hierarchical (directory) grouping, but
28           no slash-separated component can begin with a dot .  or end with
29           the sequence .lock.
30
31        2. They must contain at least one /. This enforces the presence of a
32           category like heads/, tags/ etc. but the actual names are not
33           restricted. If the --allow-onelevel option is used, this rule is
34           waived.
35
36        3. They cannot have two consecutive dots ..  anywhere.
37
38        4. They cannot have ASCII control characters (i.e. bytes whose values
39           are lower than \040, or \177 DEL), space, tilde ~, caret ^, or
40           colon : anywhere.
41
42        5. They cannot have question-mark ?, asterisk *, or open bracket [
43           anywhere. See the --refspec-pattern option below for an exception
44           to this rule.
45
46        6. They cannot begin or end with a slash / or contain multiple
47           consecutive slashes (see the --normalize option below for an
48           exception to this rule)
49
50        7. They cannot end with a dot ..
51
52        8. They cannot contain a sequence @{.
53
54        9. They cannot be the single character @.
55
56       10. They cannot contain a \.
57
58       These rules make it easy for shell script based tools to parse
59       reference names, pathname expansion by the shell when a reference name
60       is used unquoted (by mistake), and also avoid ambiguities in certain
61       reference name expressions (see gitrevisions(7)):
62
63        1. A double-dot ..  is often used as in ref1..ref2, and in some
64           contexts this notation means ^ref1 ref2 (i.e. not in ref1 and in
65           ref2).
66
67        2. A tilde ~ and caret ^ are used to introduce the postfix nth parent
68           and peel onion operation.
69
70        3. A colon : is used as in srcref:dstref to mean "use srcref’s value
71           and store it in dstref" in fetch and push operations. It may also
72           be used to select a specific object such as with git cat-file: "git
73           cat-file blob v1.3.3:refs.c".
74
75        4. at-open-brace @{ is used as a notation to access a reflog entry.
76
77       With the --branch option, the command takes a name and checks if it can
78       be used as a valid branch name (e.g. when creating a new branch). But
79       be cautious when using the previous checkout syntax that may refer to a
80       detached HEAD state. The rule git check-ref-format --branch $name
81       implements may be stricter than what git check-ref-format
82       refs/heads/$name says (e.g. a dash may appear at the beginning of a ref
83       component, but it is explicitly forbidden at the beginning of a branch
84       name). When run with --branch option in a repository, the input is
85       first expanded for the “previous checkout syntax” @{-n}. For example,
86       @{-1} is a way to refer the last thing that was checked out using "git
87       switch" or "git checkout" operation. This option should be used by
88       porcelains to accept this syntax anywhere a branch name is expected, so
89       they can act as if you typed the branch name. As an exception note
90       that, the “previous checkout operation” might result in a commit object
91       name when the N-th last thing checked out was not a branch.
92

OPTIONS

94       --[no-]allow-onelevel
95           Controls whether one-level refnames are accepted (i.e., refnames
96           that do not contain multiple /-separated components). The default
97           is --no-allow-onelevel.
98
99       --refspec-pattern
100           Interpret <refname> as a reference name pattern for a refspec (as
101           used with remote repositories). If this option is enabled,
102           <refname> is allowed to contain a single * in the refspec (e.g.,
103           foo/bar*/baz or foo/bar*baz/ but not foo/bar*/baz*).
104
105       --normalize
106           Normalize refname by removing any leading slash (/) characters and
107           collapsing runs of adjacent slashes between name components into a
108           single slash. If the normalized refname is valid then print it to
109           standard output and exit with a status of 0, otherwise exit with a
110           non-zero status. (--print is a deprecated way to spell
111           --normalize.)
112

EXAMPLES

114       ·   Print the name of the previous thing checked out:
115
116               $ git check-ref-format --branch @{-1}
117
118
119       ·   Determine the reference name to use for a new branch:
120
121               $ ref=$(git check-ref-format --normalize "refs/heads/$newbranch")||
122               { echo "we do not like '$newbranch' as a branch name." >&2 ; exit 1 ; }
123
124

GIT

126       Part of the git(1) suite
127
128
129
130Git 2.24.1                        12/10/2019              GIT-CHECK-REF-FOR(1)
Impressum