blob: ec1739a896074c96bd94603592ca72bcee0b927f [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 Hamano58700662011-10-10 23:42:2711'git check-ref-format' [--normalize]
12 [--[no-]allow-onelevel] [--refspec-pattern]
13 <refname>
Junio C Hamano3d23a0a2009-10-19 08:04:3014'git check-ref-format' --branch <branchname-shorthand>
Junio C Hamano1a4e8412005-12-27 08:17:2315
16DESCRIPTION
17-----------
Junio C Hamano1de75722009-03-26 08:39:3818Checks if a given 'refname' is acceptable, and exits with a non-zero
19status if it is not.
Junio C Hamano1a4e8412005-12-27 08:17:2320
Junio C Hamano076ffcc2013-02-06 05:13:2121A reference is used in Git to specify branches and tags. A
Junio C Hamano360e3a12011-07-13 23:51:5622branch head is stored in the `refs/heads` hierarchy, while
23a tag is stored in the `refs/tags` hierarchy of the ref namespace
24(typically in `$GIT_DIR/refs/heads` and `$GIT_DIR/refs/tags`
25directories or, as entries in file `$GIT_DIR/packed-refs`
26if refs are packed by `git gc`).
27
Junio C Hamano076ffcc2013-02-06 05:13:2128Git imposes the following rules on how references are named:
Junio C Hamano1a4e8412005-12-27 08:17:2329
Junio C Hamano1de75722009-03-26 08:39:3830. They can include slash `/` for hierarchical (directory)
Junio C Hamano33db4372006-06-07 19:51:4531 grouping, but no slash-separated component can begin with a
Junio C Hamano58700662011-10-10 23:42:2732 dot `.` or end with the sequence `.lock`.
Junio C Hamano1a4e8412005-12-27 08:17:2333
Junio C Hamano8679a792009-05-13 20:50:3234. They must contain at least one `/`. This enforces the presence of a
35 category like `heads/`, `tags/` etc. but the actual names are not
Junio C Hamano58700662011-10-10 23:42:2736 restricted. If the `--allow-onelevel` option is used, this rule
37 is waived.
Junio C Hamano8679a792009-05-13 20:50:3238
Junio C Hamano1de75722009-03-26 08:39:3839. They cannot have two consecutive dots `..` anywhere.
Junio C Hamano1a4e8412005-12-27 08:17:2340
Junio C Hamano1de75722009-03-26 08:39:3841. They cannot have ASCII control characters (i.e. bytes whose
Junio C Hamano1a4e8412005-12-27 08:17:2342 values are lower than \040, or \177 `DEL`), space, tilde `~`,
Junio C Hamanob76a6862012-05-02 22:02:4643 caret `^`, or colon `:` anywhere.
Junio C Hamano1a4e8412005-12-27 08:17:2344
Junio C Hamanob76a6862012-05-02 22:02:4645. They cannot have question-mark `?`, asterisk `*`, or open
Junio C Hamano58700662011-10-10 23:42:2746 bracket `[` anywhere. See the `--refspec-pattern` option below for
47 an exception to this rule.
Junio C Hamano5f9a6f02009-04-06 08:26:5648
Junio C Hamano58700662011-10-10 23:42:2749. 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 `.`.
Junio C Hamano5f9a6f02009-04-06 08:26:5654
55. They cannot contain a sequence `@{`.
Junio C Hamano1a4e8412005-12-27 08:17:2356
Junio C Hamanodca34822010-02-13 01:02:5257. They cannot contain a `\`.
Junio C Hamano7ae18252009-05-23 09:53:3258
Junio C Hamano1de75722009-03-26 08:39:3859These rules make it easy for shell script based tools to parse
60reference names, pathname expansion by the shell when a reference name is used
Junio C Hamano1a4e8412005-12-27 08:17:2361unquoted (by mistake), and also avoids ambiguities in certain
Junio C Hamanoc27b7332010-10-14 04:37:2862reference name expressions (see linkgit:gitrevisions[7]):
Junio C Hamano1a4e8412005-12-27 08:17:2363
Junio C Hamano1de75722009-03-26 08:39:3864. A double-dot `..` is often used as in `ref1..ref2`, and in some
Junio C Hamanob76a6862012-05-02 22:02:4665 contexts this notation means `^ref1 ref2` (i.e. not in
Junio C Hamano1de75722009-03-26 08:39:3866 `ref1` and in `ref2`).
Junio C Hamano1a4e8412005-12-27 08:17:2367
Junio C Hamanob76a6862012-05-02 22:02:4668. A tilde `~` and caret `^` are used to introduce the postfix
Junio C Hamano1a4e8412005-12-27 08:17:2369 'nth parent' and 'peel onion' operation.
70
Junio C Hamano1de75722009-03-26 08:39:3871. A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s
Junio C Hamano1a4e8412005-12-27 08:17:2372 value and store it in dstref" in fetch and push operations.
Junio C Hamanob2f5edd2006-05-21 10:50:0973 It may also be used to select a specific object such as with
Junio C Hamano1aa40d22010-01-21 17:46:4374 'git cat-file': "git cat-file blob v1.3.3:refs.c".
Junio C Hamano1a4e8412005-12-27 08:17:2375
Junio C Hamano5f9a6f02009-04-06 08:26:5676. at-open-brace `@{` is used as a notation to access a reflog entry.
77
Junio C Hamano3d23a0a2009-10-19 08:04:3078With the `--branch` option, it expands the ``previous branch syntax''
79`@{-n}`. For example, `@{-1}` is a way to refer the last branch you
80were on. This option should be used by porcelains to accept this
81syntax anywhere a branch name is expected, so they can act as if you
82typed the branch name.
Junio C Hamano5f9a6f02009-04-06 08:26:5683
Junio C Hamano58700662011-10-10 23:42:2784OPTIONS
85-------
86--allow-onelevel::
87--no-allow-onelevel::
88Controls whether one-level refnames are accepted (i.e.,
89refnames that do not contain multiple `/`-separated
90components). The default is `--no-allow-onelevel`.
91
92--refspec-pattern::
93Interpret <refname> as a reference name pattern for a refspec
94(as used with remote repositories). If this option is
Junio C Hamanob76a6862012-05-02 22:02:4695enabled, <refname> is allowed to contain a single `*`
Junio C Hamano58700662011-10-10 23:42:2796in place of a one full pathname component (e.g.,
Junio C Hamanob76a6862012-05-02 22:02:4697`foo/*/bar` but not `foo/bar*`).
Junio C Hamano58700662011-10-10 23:42:2798
99--normalize::
100Normalize 'refname' by removing any leading slash (`/`)
101characters and collapsing runs of adjacent slashes between
102name components into a single slash. Iff the normalized
103refname is valid then print it to standard output and exit
104with a status of 0. (`--print` is a deprecated way to spell
105`--normalize`.)
106
107
Junio C Hamanoc21ab052009-10-31 04:03:55108EXAMPLES
109--------
Junio C Hamano5f9a6f02009-04-06 08:26:56110
Junio C Hamanoc21ab052009-10-31 04:03:55111* Print the name of the previous branch:
112+
113------------
114$ git check-ref-format --branch @{-1}
115------------
Junio C Hamano5f9a6f02009-04-06 08:26:56116
Junio C Hamanoc21ab052009-10-31 04:03:55117* Determine the reference name to use for a new branch:
118+
119------------
Junio C Hamano58700662011-10-10 23:42:27120$ ref=$(git check-ref-format --normalize "refs/heads/$newbranch") ||
Junio C Hamanoc21ab052009-10-31 04:03:55121die "we do not like '$newbranch' as a branch name."
122------------
Junio C Hamano1a4e8412005-12-27 08:17:23123
124GIT
125---
Junio C Hamanof7c042d2008-06-06 22:50:53126Part of the linkgit:git[1] suite