]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-check-ref-format.txt
Merge branch 'jn/grep-open'
[thirdparty/git.git] / Documentation / git-check-ref-format.txt
CommitLineData
622ef9df
JH
1git-check-ref-format(1)
2=======================
3
4NAME
5----
cd747dc6 6git-check-ref-format - Ensures that a reference name is well formed
622ef9df
JH
7
8SYNOPSIS
9--------
a31dca03 10[verse]
b1889c36 11'git check-ref-format' <refname>
38eedc63 12'git check-ref-format' --print <refname>
604e0cb5 13'git check-ref-format' --branch <branchname-shorthand>
622ef9df
JH
14
15DESCRIPTION
16-----------
cd747dc6
DM
17Checks if a given 'refname' is acceptable, and exits with a non-zero
18status if it is not.
622ef9df
JH
19
20A reference is used in git to specify branches and tags. A
cd747dc6 21branch head is stored under the `$GIT_DIR/refs/heads` directory, and
cc1b8d8b
JK
22a tag is stored under the `$GIT_DIR/refs/tags` directory (or, if refs
23are packed by `git gc`, as entries in the `$GIT_DIR/packed-refs` file).
24git imposes the following rules on how references are named:
622ef9df 25
cd747dc6 26. They can include slash `/` for hierarchical (directory)
37425065 27 grouping, but no slash-separated component can begin with a
cd747dc6 28 dot `.`.
622ef9df 29
1a287259
MG
30. 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.
33
cd747dc6 34. They cannot have two consecutive dots `..` anywhere.
622ef9df 35
cd747dc6 36. They cannot have ASCII control characters (i.e. bytes whose
622ef9df 37 values are lower than \040, or \177 `DEL`), space, tilde `~`,
68283999 38 caret `{caret}`, colon `:`, question-mark `?`, asterisk `*`,
cd747dc6 39 or open bracket `[` anywhere.
622ef9df 40
cbdffe40
JH
41. They cannot end with a slash `/` nor a dot `.`.
42
3e262b95
SP
43. They cannot end with the sequence `.lock`.
44
cbdffe40 45. They cannot contain a sequence `@{`.
622ef9df 46
8222153d 47. They cannot contain a `\`.
a4c2e699 48
cd747dc6
DM
49These rules make it easy for shell script based tools to parse
50reference names, pathname expansion by the shell when a reference name is used
68283999 51unquoted (by mistake), and also avoids ambiguities in certain
f028cdae 52reference name expressions (see linkgit:gitrevisions[1]):
622ef9df 53
cd747dc6
DM
54. A double-dot `..` is often used as in `ref1..ref2`, and in some
55 contexts this notation means `{caret}ref1 ref2` (i.e. not in
56 `ref1` and in `ref2`).
622ef9df 57
cd747dc6 58. A tilde `~` and caret `{caret}` are used to introduce the postfix
622ef9df
JH
59 'nth parent' and 'peel onion' operation.
60
cd747dc6 61. A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s
622ef9df 62 value and store it in dstref" in fetch and push operations.
87a56cd3 63 It may also be used to select a specific object such as with
0b444cdb 64 'git cat-file': "git cat-file blob v1.3.3:refs.c".
622ef9df 65
cbdffe40
JH
66. at-open-brace `@{` is used as a notation to access a reflog entry.
67
38eedc63
JH
68With the `--print` option, if 'refname' is acceptable, it prints the
69canonicalized name of a hypothetical reference with that name. That is,
70it prints 'refname' with any extra `/` characters removed.
71
604e0cb5
JN
72With the `--branch` option, it expands the ``previous branch syntax''
73`@{-n}`. For example, `@{-1}` is a way to refer the last branch you
74were on. This option should be used by porcelains to accept this
75syntax anywhere a branch name is expected, so they can act as if you
76typed the branch name.
a31dca03 77
38eedc63
JH
78EXAMPLES
79--------
a31dca03 80
38eedc63
JH
81* Print the name of the previous branch:
82+
83------------
84$ git check-ref-format --branch @{-1}
85------------
86
87* Determine the reference name to use for a new branch:
88+
89------------
90$ ref=$(git check-ref-format --print "refs/heads/$newbranch") ||
91die "we do not like '$newbranch' as a branch name."
92------------
622ef9df
JH
93
94GIT
95---
9e1f0a85 96Part of the linkgit:git[1] suite