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