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

DESCRIPTION

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

OPTIONS

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

EXAMPLES

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

GIT

123       Part of the git(1) suite
124
125
126
127Git 2.26.2                        2020-04-20              GIT-CHECK-REF-FOR(1)
Impressum