blob: 2aacfd18088d6506bfd8aa3ca7380888e8dbcffa [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
Junio C Hamano33be8212023-10-23 21:45:5451 exception to this rule).
Junio C Hamano58700662011-10-10 23:42:2752
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 Hamano79f4c7c2013-09-20 21:03:3757. They cannot be the single character `@`.
58
Junio C Hamanodca34822010-02-13 01:02:5259. They cannot contain a `\`.
Junio C Hamano7ae18252009-05-23 09:53:3260
Junio C Hamano1de75722009-03-26 08:39:3861These rules make it easy for shell script based tools to parse
62reference names, pathname expansion by the shell when a reference name is used
Junio C Hamanod30e7ef2015-12-10 22:27:1763unquoted (by mistake), and also avoid ambiguities in certain
Junio C Hamanoc27b7332010-10-14 04:37:2864reference name expressions (see linkgit:gitrevisions[7]):
Junio C Hamano1a4e8412005-12-27 08:17:2365
Junio C Hamano1de75722009-03-26 08:39:3866. A double-dot `..` is often used as in `ref1..ref2`, and in some
Junio C Hamanob76a6862012-05-02 22:02:4667 contexts this notation means `^ref1 ref2` (i.e. not in
Junio C Hamano1de75722009-03-26 08:39:3868 `ref1` and in `ref2`).
Junio C Hamano1a4e8412005-12-27 08:17:2369
Junio C Hamanob76a6862012-05-02 22:02:4670. A tilde `~` and caret `^` are used to introduce the postfix
Junio C Hamano1a4e8412005-12-27 08:17:2371 'nth parent' and 'peel onion' operation.
72
Junio C Hamano1de75722009-03-26 08:39:3873. A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s
Junio C Hamano1a4e8412005-12-27 08:17:2374 value and store it in dstref" in fetch and push operations.
Junio C Hamanob2f5edd2006-05-21 10:50:0975 It may also be used to select a specific object such as with
Junio C Hamano1aa40d22010-01-21 17:46:4376 'git cat-file': "git cat-file blob v1.3.3:refs.c".
Junio C Hamano1a4e8412005-12-27 08:17:2377
Junio C Hamano5f9a6f02009-04-06 08:26:5678. at-open-brace `@{` is used as a notation to access a reflog entry.
79
Junio C Hamano3a9c0342017-11-10 06:01:1280With the `--branch` option, the command takes a name and checks if
81it can be used as a valid branch name (e.g. when creating a new
Junio C Hamano68e72b72017-12-28 23:20:5282branch). But be cautious when using the
83previous checkout syntax that may refer to a detached HEAD state.
84The rule `git check-ref-format --branch $name` implements
Junio C Hamano3a9c0342017-11-10 06:01:1285may be stricter than what `git check-ref-format refs/heads/$name`
86says (e.g. a dash may appear at the beginning of a ref component,
87but it is explicitly forbidden at the beginning of a branch name).
Junio C Hamano33be8212023-10-23 21:45:5488When run with the `--branch` option in a repository, the input is first
Junio C Hamano68e72b72017-12-28 23:20:5289expanded for the ``previous checkout syntax''
90`@{-n}`. For example, `@{-1}` is a way to refer the last thing that
Junio C Hamanoc9f11c22019-07-10 02:54:0491was checked out using "git switch" or "git checkout" operation.
92This option should be
Junio C Hamano68e72b72017-12-28 23:20:5293used by porcelains to accept this syntax anywhere a branch name is
94expected, so they can act as if you typed the branch name. As an
95exception note that, the ``previous checkout operation'' might result
96in a commit object name when the N-th last thing checked out was not
97a branch.
Junio C Hamano5f9a6f02009-04-06 08:26:5698
Junio C Hamano58700662011-10-10 23:42:2799OPTIONS
100-------
Junio C Hamano3d1b5a12013-05-17 23:34:02101--[no-]allow-onelevel::
Junio C Hamano58700662011-10-10 23:42:27102Controls whether one-level refnames are accepted (i.e.,
103refnames that do not contain multiple `/`-separated
104components). The default is `--no-allow-onelevel`.
105
106--refspec-pattern::
107Interpret <refname> as a reference name pattern for a refspec
108(as used with remote repositories). If this option is
Junio C Hamanob76a6862012-05-02 22:02:46109enabled, <refname> is allowed to contain a single `*`
Junio C Hamanod7ed4042015-08-03 19:43:00110in the refspec (e.g., `foo/bar*/baz` or `foo/bar*baz/`
111but not `foo/bar*/baz*`).
Junio C Hamano58700662011-10-10 23:42:27112
113--normalize::
114Normalize 'refname' by removing any leading slash (`/`)
115characters and collapsing runs of adjacent slashes between
Junio C Hamanofa0dac32017-02-24 19:02:55116name components into a single slash. If the normalized
Junio C Hamano58700662011-10-10 23:42:27117refname is valid then print it to standard output and exit
Junio C Hamanofa0dac32017-02-24 19:02:55118with a status of 0, otherwise exit with a non-zero status.
119(`--print` is a deprecated way to spell `--normalize`.)
Junio C Hamano58700662011-10-10 23:42:27120
121
Junio C Hamanoc21ab052009-10-31 04:03:55122EXAMPLES
123--------
Junio C Hamano5f9a6f02009-04-06 08:26:56124
Junio C Hamano68e72b72017-12-28 23:20:52125* Print the name of the previous thing checked out:
Junio C Hamanoc21ab052009-10-31 04:03:55126+
127------------
128$ git check-ref-format --branch @{-1}
129------------
Junio C Hamano5f9a6f02009-04-06 08:26:56130
Junio C Hamanoc21ab052009-10-31 04:03:55131* Determine the reference name to use for a new branch:
132+
133------------
Junio C Hamanoad70bf02016-09-26 23:44:27134$ ref=$(git check-ref-format --normalize "refs/heads/$newbranch")||
135{ echo "we do not like '$newbranch' as a branch name." >&2 ; exit 1 ; }
Junio C Hamanoc21ab052009-10-31 04:03:55136------------
Junio C Hamano1a4e8412005-12-27 08:17:23137
138GIT
139---
Junio C Hamanof7c042d2008-06-06 22:50:53140Part of the linkgit:git[1] suite