blob: 379eee6734323ee566480d5f9159dd28ed27ecd2 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-check-ref-format(1)
2=======================
3
4NAME
5----
Junio C Hamano1de75722009-03-26 08:39:386git-check-ref-format - Ensures that a reference name is well formed
Junio C Hamano1a4e8412005-12-27 08:17:237
8SYNOPSIS
9--------
Junio C Hamano5f9a6f02009-04-06 08:26:5610[verse]
Junio C Hamanofce7c7e2008-07-02 03:06:3811'git check-ref-format' <refname>
Junio C Hamanoc21ab052009-10-31 04:03:5512'git check-ref-format' --print <refname>
Junio C Hamano3d23a0a2009-10-19 08:04:3013'git check-ref-format' --branch <branchname-shorthand>
Junio C Hamano1a4e8412005-12-27 08:17:2314
15DESCRIPTION
16-----------
Junio C Hamano1de75722009-03-26 08:39:3817Checks if a given 'refname' is acceptable, and exits with a non-zero
18status if it is not.
Junio C Hamano1a4e8412005-12-27 08:17:2319
20A reference is used in git to specify branches and tags. A
Junio C Hamano1de75722009-03-26 08:39:3821branch head is stored under the `$GIT_DIR/refs/heads` directory, and
Junio C Hamano4fdccb22010-02-19 09:58:1422a 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:
Junio C Hamano1a4e8412005-12-27 08:17:2325
Junio C Hamano1de75722009-03-26 08:39:3826. They can include slash `/` for hierarchical (directory)
Junio C Hamano33db4372006-06-07 19:51:4527 grouping, but no slash-separated component can begin with a
Junio C Hamano1de75722009-03-26 08:39:3828 dot `.`.
Junio C Hamano1a4e8412005-12-27 08:17:2329
Junio C Hamano8679a792009-05-13 20:50:3230. 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
Junio C Hamano1de75722009-03-26 08:39:3834. They cannot have two consecutive dots `..` anywhere.
Junio C Hamano1a4e8412005-12-27 08:17:2335
Junio C Hamano1de75722009-03-26 08:39:3836. They cannot have ASCII control characters (i.e. bytes whose
Junio C Hamano1a4e8412005-12-27 08:17:2337 values are lower than \040, or \177 `DEL`), space, tilde `~`,
38 caret `{caret}`, colon `:`, question-mark `?`, asterisk `*`,
Junio C Hamano1de75722009-03-26 08:39:3839 or open bracket `[` anywhere.
Junio C Hamano1a4e8412005-12-27 08:17:2340
Junio C Hamano5f9a6f02009-04-06 08:26:5641. They cannot end with a slash `/` nor a dot `.`.
42
43. They cannot end with the sequence `.lock`.
44
45. They cannot contain a sequence `@{`.
Junio C Hamano1a4e8412005-12-27 08:17:2346
Junio C Hamanodca34822010-02-13 01:02:5247. They cannot contain a `\`.
Junio C Hamano7ae18252009-05-23 09:53:3248
Junio C Hamano1de75722009-03-26 08:39:3849These rules make it easy for shell script based tools to parse
50reference names, pathname expansion by the shell when a reference name is used
Junio C Hamano1a4e8412005-12-27 08:17:2351unquoted (by mistake), and also avoids ambiguities in certain
Junio C Hamano1de75722009-03-26 08:39:3852reference name expressions (see linkgit:git-rev-parse[1]):
Junio C Hamano1a4e8412005-12-27 08:17:2353
Junio C Hamano1de75722009-03-26 08:39:3854. 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`).
Junio C Hamano1a4e8412005-12-27 08:17:2357
Junio C Hamano1de75722009-03-26 08:39:3858. A tilde `~` and caret `{caret}` are used to introduce the postfix
Junio C Hamano1a4e8412005-12-27 08:17:2359 'nth parent' and 'peel onion' operation.
60
Junio C Hamano1de75722009-03-26 08:39:3861. A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s
Junio C Hamano1a4e8412005-12-27 08:17:2362 value and store it in dstref" in fetch and push operations.
Junio C Hamanob2f5edd2006-05-21 10:50:0963 It may also be used to select a specific object such as with
Junio C Hamano1aa40d22010-01-21 17:46:4364 'git cat-file': "git cat-file blob v1.3.3:refs.c".
Junio C Hamano1a4e8412005-12-27 08:17:2365
Junio C Hamano5f9a6f02009-04-06 08:26:5666. at-open-brace `@{` is used as a notation to access a reflog entry.
67
Junio C Hamanoc21ab052009-10-31 04:03:5568With 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
Junio C Hamano3d23a0a2009-10-19 08:04:3072With 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.
Junio C Hamano5f9a6f02009-04-06 08:26:5677
Junio C Hamanoc21ab052009-10-31 04:03:5578EXAMPLES
79--------
Junio C Hamano5f9a6f02009-04-06 08:26:5680
Junio C Hamanoc21ab052009-10-31 04:03:5581* Print the name of the previous branch:
82+
83------------
84$ git check-ref-format --branch @{-1}
85------------
Junio C Hamano5f9a6f02009-04-06 08:26:5686
Junio C Hamanoc21ab052009-10-31 04:03:5587* 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------------
Junio C Hamano1a4e8412005-12-27 08:17:2393
94GIT
95---
Junio C Hamanof7c042d2008-06-06 22:50:5396Part of the linkgit:git[1] suite