]>
Commit | Line | Data |
---|---|---|
622ef9df JH |
1 | git-check-ref-format(1) |
2 | ======================= | |
3 | ||
4 | NAME | |
5 | ---- | |
cd747dc6 | 6 | git-check-ref-format - Ensures that a reference name is well formed |
622ef9df JH |
7 | |
8 | SYNOPSIS | |
9 | -------- | |
a31dca03 | 10 | [verse] |
a40e6fb6 MH |
11 | 'git check-ref-format' [--normalize] |
12 | [--[no-]allow-onelevel] [--refspec-pattern] | |
13 | <refname> | |
604e0cb5 | 14 | 'git check-ref-format' --branch <branchname-shorthand> |
622ef9df JH |
15 | |
16 | DESCRIPTION | |
17 | ----------- | |
cd747dc6 DM |
18 | Checks if a given 'refname' is acceptable, and exits with a non-zero |
19 | status if it is not. | |
622ef9df | 20 | |
2de9b711 | 21 | A reference is used in Git to specify branches and tags. A |
a0a7e9e5 JH |
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`). | |
27 | ||
2de9b711 | 28 | Git imposes the following rules on how references are named: |
622ef9df | 29 | |
cd747dc6 | 30 | . They can include slash `/` for hierarchical (directory) |
37425065 | 31 | grouping, but no slash-separated component can begin with a |
7e9d2fe9 | 32 | dot `.` or end with the sequence `.lock`. |
622ef9df | 33 | |
1a287259 MG |
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 | |
e4ed6105 MH |
36 | restricted. If the `--allow-onelevel` option is used, this rule |
37 | is waived. | |
1a287259 | 38 | |
cd747dc6 | 39 | . They cannot have two consecutive dots `..` anywhere. |
622ef9df | 40 | |
cd747dc6 | 41 | . They cannot have ASCII control characters (i.e. bytes whose |
622ef9df | 42 | values are lower than \040, or \177 `DEL`), space, tilde `~`, |
6cf378f0 | 43 | caret `^`, or colon `:` anywhere. |
e4ed6105 | 44 | |
6cf378f0 | 45 | . They cannot have question-mark `?`, asterisk `*`, or open |
e4ed6105 MH |
46 | bracket `[` anywhere. See the `--refspec-pattern` option below for |
47 | an exception to this rule. | |
622ef9df | 48 | |
a40e6fb6 MH |
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) | |
52 | ||
53 | . They cannot end with a dot `.`. | |
cbdffe40 JH |
54 | |
55 | . They cannot contain a sequence `@{`. | |
622ef9df | 56 | |
9ba89f48 FC |
57 | . They cannot be the single character `@`. |
58 | ||
8222153d | 59 | . They cannot contain a `\`. |
a4c2e699 | 60 | |
cd747dc6 DM |
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 | |
56a8aea0 | 63 | unquoted (by mistake), and also avoid ambiguities in certain |
9d83e382 | 64 | reference name expressions (see linkgit:gitrevisions[7]): |
622ef9df | 65 | |
cd747dc6 | 66 | . A double-dot `..` is often used as in `ref1..ref2`, and in some |
6cf378f0 | 67 | contexts this notation means `^ref1 ref2` (i.e. not in |
cd747dc6 | 68 | `ref1` and in `ref2`). |
622ef9df | 69 | |
6cf378f0 | 70 | . A tilde `~` and caret `^` are used to introduce the postfix |
622ef9df JH |
71 | 'nth parent' and 'peel onion' operation. |
72 | ||
cd747dc6 | 73 | . A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s |
622ef9df | 74 | value and store it in dstref" in fetch and push operations. |
87a56cd3 | 75 | It may also be used to select a specific object such as with |
0b444cdb | 76 | 'git cat-file': "git cat-file blob v1.3.3:refs.c". |
622ef9df | 77 | |
cbdffe40 JH |
78 | . at-open-brace `@{` is used as a notation to access a reflog entry. |
79 | ||
89dd32ae JH |
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 | |
c6342e05 KS |
82 | branch). But be cautious when using the |
83 | previous checkout syntax that may refer to a detached HEAD state. | |
84 | The rule `git check-ref-format --branch $name` implements | |
89dd32ae JH |
85 | may be stricter than what `git check-ref-format refs/heads/$name` |
86 | says (e.g. a dash may appear at the beginning of a ref component, | |
87 | but it is explicitly forbidden at the beginning of a branch name). | |
88 | When run with `--branch` option in a repository, the input is first | |
c6342e05 KS |
89 | expanded for the ``previous checkout syntax'' |
90 | `@{-n}`. For example, `@{-1}` is a way to refer the last thing that | |
328c6cb8 NTND |
91 | was checked out using "git switch" or "git checkout" operation. |
92 | This option should be | |
c6342e05 KS |
93 | used by porcelains to accept this syntax anywhere a branch name is |
94 | expected, so they can act as if you typed the branch name. As an | |
95 | exception note that, the ``previous checkout operation'' might result | |
96 | in a commit object name when the N-th last thing checked out was not | |
97 | a branch. | |
a31dca03 | 98 | |
e4ed6105 MH |
99 | OPTIONS |
100 | ------- | |
0460ed2c | 101 | --[no-]allow-onelevel:: |
e4ed6105 MH |
102 | Controls whether one-level refnames are accepted (i.e., |
103 | refnames that do not contain multiple `/`-separated | |
104 | components). The default is `--no-allow-onelevel`. | |
105 | ||
106 | --refspec-pattern:: | |
107 | Interpret <refname> as a reference name pattern for a refspec | |
108 | (as used with remote repositories). If this option is | |
6cf378f0 | 109 | enabled, <refname> is allowed to contain a single `*` |
cd377f45 JK |
110 | in the refspec (e.g., `foo/bar*/baz` or `foo/bar*baz/` |
111 | but not `foo/bar*/baz*`). | |
e4ed6105 | 112 | |
a40e6fb6 MH |
113 | --normalize:: |
114 | Normalize 'refname' by removing any leading slash (`/`) | |
115 | characters and collapsing runs of adjacent slashes between | |
115a40ad | 116 | name components into a single slash. If the normalized |
a40e6fb6 | 117 | refname is valid then print it to standard output and exit |
115a40ad DR |
118 | with a status of 0, otherwise exit with a non-zero status. |
119 | (`--print` is a deprecated way to spell `--normalize`.) | |
a40e6fb6 MH |
120 | |
121 | ||
38eedc63 JH |
122 | EXAMPLES |
123 | -------- | |
a31dca03 | 124 | |
c6342e05 | 125 | * Print the name of the previous thing checked out: |
38eedc63 JH |
126 | + |
127 | ------------ | |
128 | $ git check-ref-format --branch @{-1} | |
129 | ------------ | |
130 | ||
131 | * Determine the reference name to use for a new branch: | |
132 | + | |
133 | ------------ | |
92dece70 EP |
134 | $ ref=$(git check-ref-format --normalize "refs/heads/$newbranch")|| |
135 | { echo "we do not like '$newbranch' as a branch name." >&2 ; exit 1 ; } | |
38eedc63 | 136 | ------------ |
622ef9df JH |
137 | |
138 | GIT | |
139 | --- | |
9e1f0a85 | 140 | Part of the linkgit:git[1] suite |