1 git-check-ref-format(1)
2 =======================
6 git-check-ref-format - Ensures that a reference name is well formed
11 'git check-ref-format' [--normalize]
12 [--[no-]allow-onelevel] [--refspec-pattern]
14 'git check-ref-format' --branch <branchname-shorthand>
18 Checks if a given 'refname' is acceptable, and exits with a non-zero
21 A reference is used in Git to specify branches and tags. A
22 branch head is stored in the `refs/heads` hierarchy, while
23 a tag is stored in the `refs/tags` hierarchy of the ref namespace
24 (typically in `$GIT_DIR/refs/heads` and `$GIT_DIR/refs/tags`
25 directories or, as entries in file `$GIT_DIR/packed-refs`
26 if refs are packed by `git gc`).
28 Git imposes the following rules on how references are named:
30 . They can include slash `/` for hierarchical (directory)
31 grouping, but no slash-separated component can begin with a
32 dot `.` or end with the sequence `.lock`.
34 . They must contain at least one `/`. This enforces the presence of a
35 category like `heads/`, `tags/` etc. but the actual names are not
36 restricted. If the `--allow-onelevel` option is used, this rule
39 . They cannot have two consecutive dots `..` anywhere.
41 . They cannot have ASCII control characters (i.e. bytes whose
42 values are lower than \040, or \177 `DEL`), space, tilde `~`,
43 caret `^`, or colon `:` anywhere.
45 . They cannot have question-mark `?`, asterisk `*`, or open
46 bracket `[` anywhere. See the `--refspec-pattern` option below for
47 an exception to this rule.
49 . They cannot begin or end with a slash `/` or contain multiple
50 consecutive slashes (see the `--normalize` option below for an
51 exception to this rule)
53 . They cannot end with a dot `.`.
55 . They cannot contain a sequence `@{`.
57 . They cannot be the single character `@`.
59 . They cannot contain a `\`.
61 These rules make it easy for shell script based tools to parse
62 reference names, pathname expansion by the shell when a reference name is used
63 unquoted (by mistake), and also avoid ambiguities in certain
64 reference name expressions (see linkgit:gitrevisions[7]):
66 . A double-dot `..` is often used as in `ref1..ref2`, and in some
67 contexts this notation means `^ref1 ref2` (i.e. not in
68 `ref1` and in `ref2`).
70 . A tilde `~` and caret `^` are used to introduce the postfix
71 'nth parent' and 'peel onion' operation.
73 . A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s
74 value and store it in dstref" in fetch and push operations.
75 It may also be used to select a specific object such as with
76 'git cat-file': "git cat-file blob v1.3.3:refs.c".
78 . at-open-brace `@{` is used as a notation to access a reflog entry.
80 With the `--branch` option, the command takes a name and checks if
81 it can be used as a valid branch name (e.g. when creating a new
82 branch). The rule `git check-ref-format --branch $name` implements
83 may be stricter than what `git check-ref-format refs/heads/$name`
84 says (e.g. a dash may appear at the beginning of a ref component,
85 but it is explicitly forbidden at the beginning of a branch name).
86 When run with `--branch` option in a repository, the input is first
87 expanded for the ``previous branch syntax''
88 `@{-n}`. For example, `@{-1}` is a way to refer the last branch you
89 were on. This option should be used by porcelains to accept this
90 syntax anywhere a branch name is expected, so they can act as if you
91 typed the branch name.
95 --[no-]allow-onelevel::
96 Controls whether one-level refnames are accepted (i.e.,
97 refnames that do not contain multiple `/`-separated
98 components). The default is `--no-allow-onelevel`.
101 Interpret <refname> as a reference name pattern for a refspec
102 (as used with remote repositories). If this option is
103 enabled, <refname> is allowed to contain a single `*`
104 in the refspec (e.g., `foo/bar*/baz` or `foo/bar*baz/`
105 but not `foo/bar*/baz*`).
108 Normalize 'refname' by removing any leading slash (`/`)
109 characters and collapsing runs of adjacent slashes between
110 name components into a single slash. If the normalized
111 refname is valid then print it to standard output and exit
112 with a status of 0, otherwise exit with a non-zero status.
113 (`--print` is a deprecated way to spell `--normalize`.)
119 * Print the name of the previous branch:
122 $ git check-ref-format --branch @{-1}
125 * Determine the reference name to use for a new branch:
128 $ ref=$(git check-ref-format --normalize "refs/heads/$newbranch")||
129 { echo "we do not like '$newbranch' as a branch name." >&2 ; exit 1 ; }
134 Part of the linkgit:git[1] suite