]>
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] |
e4ed6105 MH |
11 | 'git check-ref-format' [--print] |
12 | [--[no-]allow-onelevel] [--refspec-pattern] <refname> | |
604e0cb5 | 13 | 'git check-ref-format' --branch <branchname-shorthand> |
622ef9df JH |
14 | |
15 | DESCRIPTION | |
16 | ----------- | |
cd747dc6 DM |
17 | Checks if a given 'refname' is acceptable, and exits with a non-zero |
18 | status if it is not. | |
622ef9df JH |
19 | |
20 | A reference is used in git to specify branches and tags. A | |
a0a7e9e5 JH |
21 | branch head is stored in the `refs/heads` hierarchy, while |
22 | a tag is stored in the `refs/tags` hierarchy of the ref namespace | |
23 | (typically in `$GIT_DIR/refs/heads` and `$GIT_DIR/refs/tags` | |
24 | directories or, as entries in file `$GIT_DIR/packed-refs` | |
25 | if refs are packed by `git gc`). | |
26 | ||
cc1b8d8b | 27 | git imposes the following rules on how references are named: |
622ef9df | 28 | |
cd747dc6 | 29 | . They can include slash `/` for hierarchical (directory) |
37425065 | 30 | grouping, but no slash-separated component can begin with a |
7e9d2fe9 | 31 | dot `.` or end with the sequence `.lock`. |
622ef9df | 32 | |
1a287259 MG |
33 | . They must contain at least one `/`. This enforces the presence of a |
34 | category like `heads/`, `tags/` etc. but the actual names are not | |
e4ed6105 MH |
35 | restricted. If the `--allow-onelevel` option is used, this rule |
36 | is waived. | |
1a287259 | 37 | |
cd747dc6 | 38 | . They cannot have two consecutive dots `..` anywhere. |
622ef9df | 39 | |
cd747dc6 | 40 | . They cannot have ASCII control characters (i.e. bytes whose |
622ef9df | 41 | values are lower than \040, or \177 `DEL`), space, tilde `~`, |
e4ed6105 MH |
42 | caret `{caret}`, or colon `:` anywhere. |
43 | ||
44 | . They cannot have question-mark `?`, asterisk `{asterisk}`, or open | |
45 | bracket `[` anywhere. See the `--refspec-pattern` option below for | |
46 | an exception to this rule. | |
622ef9df | 47 | |
cbdffe40 JH |
48 | . They cannot end with a slash `/` nor a dot `.`. |
49 | ||
50 | . They cannot contain a sequence `@{`. | |
622ef9df | 51 | |
8222153d | 52 | . They cannot contain a `\`. |
a4c2e699 | 53 | |
cd747dc6 DM |
54 | These rules make it easy for shell script based tools to parse |
55 | reference names, pathname expansion by the shell when a reference name is used | |
68283999 | 56 | unquoted (by mistake), and also avoids ambiguities in certain |
9d83e382 | 57 | reference name expressions (see linkgit:gitrevisions[7]): |
622ef9df | 58 | |
cd747dc6 DM |
59 | . A double-dot `..` is often used as in `ref1..ref2`, and in some |
60 | contexts this notation means `{caret}ref1 ref2` (i.e. not in | |
61 | `ref1` and in `ref2`). | |
622ef9df | 62 | |
cd747dc6 | 63 | . A tilde `~` and caret `{caret}` are used to introduce the postfix |
622ef9df JH |
64 | 'nth parent' and 'peel onion' operation. |
65 | ||
cd747dc6 | 66 | . A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s |
622ef9df | 67 | value and store it in dstref" in fetch and push operations. |
87a56cd3 | 68 | It may also be used to select a specific object such as with |
0b444cdb | 69 | 'git cat-file': "git cat-file blob v1.3.3:refs.c". |
622ef9df | 70 | |
cbdffe40 JH |
71 | . at-open-brace `@{` is used as a notation to access a reflog entry. |
72 | ||
38eedc63 JH |
73 | With the `--print` option, if 'refname' is acceptable, it prints the |
74 | canonicalized name of a hypothetical reference with that name. That is, | |
75 | it prints 'refname' with any extra `/` characters removed. | |
76 | ||
604e0cb5 JN |
77 | With the `--branch` option, it expands the ``previous branch syntax'' |
78 | `@{-n}`. For example, `@{-1}` is a way to refer the last branch you | |
79 | were on. This option should be used by porcelains to accept this | |
80 | syntax anywhere a branch name is expected, so they can act as if you | |
81 | typed the branch name. | |
a31dca03 | 82 | |
e4ed6105 MH |
83 | OPTIONS |
84 | ------- | |
85 | --allow-onelevel:: | |
86 | --no-allow-onelevel:: | |
87 | Controls whether one-level refnames are accepted (i.e., | |
88 | refnames that do not contain multiple `/`-separated | |
89 | components). The default is `--no-allow-onelevel`. | |
90 | ||
91 | --refspec-pattern:: | |
92 | Interpret <refname> as a reference name pattern for a refspec | |
93 | (as used with remote repositories). If this option is | |
94 | enabled, <refname> is allowed to contain a single `{asterisk}` | |
95 | in place of a one full pathname component (e.g., | |
96 | `foo/{asterisk}/bar` but not `foo/bar{asterisk}`). | |
97 | ||
38eedc63 JH |
98 | EXAMPLES |
99 | -------- | |
a31dca03 | 100 | |
38eedc63 JH |
101 | * Print the name of the previous branch: |
102 | + | |
103 | ------------ | |
104 | $ git check-ref-format --branch @{-1} | |
105 | ------------ | |
106 | ||
107 | * Determine the reference name to use for a new branch: | |
108 | + | |
109 | ------------ | |
110 | $ ref=$(git check-ref-format --print "refs/heads/$newbranch") || | |
111 | die "we do not like '$newbranch' as a branch name." | |
112 | ------------ | |
622ef9df JH |
113 | |
114 | GIT | |
115 | --- | |
9e1f0a85 | 116 | Part of the linkgit:git[1] suite |