Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | git-check-ref-format(1) |
| 2 | ======================= |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 6 | git-check-ref-format - Ensures that a reference name is well formed |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 10 | [verse] |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 11 | 'git check-ref-format' [--normalize] |
| 12 | [--[no-]allow-onelevel] [--refspec-pattern] |
| 13 | <refname> |
Junio C Hamano | 3d23a0a | 2009-10-19 08:04:30 | [diff] [blame] | 14 | 'git check-ref-format' --branch <branchname-shorthand> |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 15 | |
| 16 | DESCRIPTION |
| 17 | ----------- |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 18 | Checks if a given 'refname' is acceptable, and exits with a non-zero |
| 19 | status if it is not. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 20 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 21 | A reference is used in Git to specify branches and tags. A |
Junio C Hamano | 360e3a1 | 2011-07-13 23:51:56 | [diff] [blame] | 22 | branch head is stored in the `refs/heads` hierarchy, while |
| 23 | a tag is stored in the `refs/tags` hierarchy of the ref namespace |
| 24 | (typically in `$GIT_DIR/refs/heads` and `$GIT_DIR/refs/tags` |
| 25 | directories or, as entries in file `$GIT_DIR/packed-refs` |
| 26 | if refs are packed by `git gc`). |
| 27 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 28 | Git imposes the following rules on how references are named: |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 29 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 30 | . They can include slash `/` for hierarchical (directory) |
Junio C Hamano | 33db437 | 2006-06-07 19:51:45 | [diff] [blame] | 31 | grouping, but no slash-separated component can begin with a |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 32 | dot `.` or end with the sequence `.lock`. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 33 | |
Junio C Hamano | 8679a79 | 2009-05-13 20:50:32 | [diff] [blame] | 34 | . 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 Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 36 | restricted. If the `--allow-onelevel` option is used, this rule |
| 37 | is waived. |
Junio C Hamano | 8679a79 | 2009-05-13 20:50:32 | [diff] [blame] | 38 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 39 | . They cannot have two consecutive dots `..` anywhere. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 40 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 41 | . They cannot have ASCII control characters (i.e. bytes whose |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 42 | values are lower than \040, or \177 `DEL`), space, tilde `~`, |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 43 | caret `^`, or colon `:` anywhere. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 44 | |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 45 | . They cannot have question-mark `?`, asterisk `*`, or open |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 46 | bracket `[` anywhere. See the `--refspec-pattern` option below for |
| 47 | an exception to this rule. |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 48 | |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 49 | . They cannot begin or end with a slash `/` or contain multiple |
| 50 | consecutive slashes (see the `--normalize` option below for an |
Junio C Hamano | 33be821 | 2023-10-23 21:45:54 | [diff] [blame] | 51 | exception to this rule). |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 52 | |
| 53 | . They cannot end with a dot `.`. |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 54 | |
| 55 | . They cannot contain a sequence `@{`. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 56 | |
Junio C Hamano | 79f4c7c | 2013-09-20 21:03:37 | [diff] [blame] | 57 | . They cannot be the single character `@`. |
| 58 | |
Junio C Hamano | dca3482 | 2010-02-13 01:02:52 | [diff] [blame] | 59 | . They cannot contain a `\`. |
Junio C Hamano | 7ae1825 | 2009-05-23 09:53:32 | [diff] [blame] | 60 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 61 | These rules make it easy for shell script based tools to parse |
| 62 | reference names, pathname expansion by the shell when a reference name is used |
Junio C Hamano | d30e7ef | 2015-12-10 22:27:17 | [diff] [blame] | 63 | unquoted (by mistake), and also avoid ambiguities in certain |
Junio C Hamano | c27b733 | 2010-10-14 04:37:28 | [diff] [blame] | 64 | reference name expressions (see linkgit:gitrevisions[7]): |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 65 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 66 | . A double-dot `..` is often used as in `ref1..ref2`, and in some |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 67 | contexts this notation means `^ref1 ref2` (i.e. not in |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 68 | `ref1` and in `ref2`). |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 69 | |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 70 | . A tilde `~` and caret `^` are used to introduce the postfix |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 71 | 'nth parent' and 'peel onion' operation. |
| 72 | |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 73 | . A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 74 | value and store it in dstref" in fetch and push operations. |
Junio C Hamano | b2f5edd | 2006-05-21 10:50:09 | [diff] [blame] | 75 | It may also be used to select a specific object such as with |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 76 | 'git cat-file': "git cat-file blob v1.3.3:refs.c". |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 77 | |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 78 | . at-open-brace `@{` is used as a notation to access a reflog entry. |
| 79 | |
Junio C Hamano | 3a9c034 | 2017-11-10 06:01:12 | [diff] [blame] | 80 | With the `--branch` option, the command takes a name and checks if |
| 81 | it can be used as a valid branch name (e.g. when creating a new |
Junio C Hamano | 68e72b7 | 2017-12-28 23:20:52 | [diff] [blame] | 82 | branch). But be cautious when using the |
| 83 | previous checkout syntax that may refer to a detached HEAD state. |
| 84 | The rule `git check-ref-format --branch $name` implements |
Junio C Hamano | 3a9c034 | 2017-11-10 06:01:12 | [diff] [blame] | 85 | may be stricter than what `git check-ref-format refs/heads/$name` |
| 86 | says (e.g. a dash may appear at the beginning of a ref component, |
| 87 | but it is explicitly forbidden at the beginning of a branch name). |
Junio C Hamano | 33be821 | 2023-10-23 21:45:54 | [diff] [blame] | 88 | When run with the `--branch` option in a repository, the input is first |
Junio C Hamano | 68e72b7 | 2017-12-28 23:20:52 | [diff] [blame] | 89 | expanded for the ``previous checkout syntax'' |
| 90 | `@{-n}`. For example, `@{-1}` is a way to refer the last thing that |
Junio C Hamano | c9f11c2 | 2019-07-10 02:54:04 | [diff] [blame] | 91 | was checked out using "git switch" or "git checkout" operation. |
| 92 | This option should be |
Junio C Hamano | 68e72b7 | 2017-12-28 23:20:52 | [diff] [blame] | 93 | used by porcelains to accept this syntax anywhere a branch name is |
| 94 | expected, so they can act as if you typed the branch name. As an |
| 95 | exception note that, the ``previous checkout operation'' might result |
| 96 | in a commit object name when the N-th last thing checked out was not |
| 97 | a branch. |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 98 | |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 99 | OPTIONS |
| 100 | ------- |
Junio C Hamano | 3d1b5a1 | 2013-05-17 23:34:02 | [diff] [blame] | 101 | --[no-]allow-onelevel:: |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 102 | Controls whether one-level refnames are accepted (i.e., |
| 103 | refnames that do not contain multiple `/`-separated |
| 104 | components). The default is `--no-allow-onelevel`. |
| 105 | |
| 106 | --refspec-pattern:: |
| 107 | Interpret <refname> as a reference name pattern for a refspec |
| 108 | (as used with remote repositories). If this option is |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 109 | enabled, <refname> is allowed to contain a single `*` |
Junio C Hamano | d7ed404 | 2015-08-03 19:43:00 | [diff] [blame] | 110 | in the refspec (e.g., `foo/bar*/baz` or `foo/bar*baz/` |
| 111 | but not `foo/bar*/baz*`). |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 112 | |
| 113 | --normalize:: |
| 114 | Normalize 'refname' by removing any leading slash (`/`) |
| 115 | characters and collapsing runs of adjacent slashes between |
Junio C Hamano | fa0dac3 | 2017-02-24 19:02:55 | [diff] [blame] | 116 | name components into a single slash. If the normalized |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 117 | refname is valid then print it to standard output and exit |
Junio C Hamano | fa0dac3 | 2017-02-24 19:02:55 | [diff] [blame] | 118 | with a status of 0, otherwise exit with a non-zero status. |
| 119 | (`--print` is a deprecated way to spell `--normalize`.) |
Junio C Hamano | 5870066 | 2011-10-10 23:42:27 | [diff] [blame] | 120 | |
| 121 | |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 122 | EXAMPLES |
| 123 | -------- |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 124 | |
Junio C Hamano | 68e72b7 | 2017-12-28 23:20:52 | [diff] [blame] | 125 | * Print the name of the previous thing checked out: |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 126 | + |
| 127 | ------------ |
| 128 | $ git check-ref-format --branch @{-1} |
| 129 | ------------ |
Junio C Hamano | 5f9a6f0 | 2009-04-06 08:26:56 | [diff] [blame] | 130 | |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 131 | * Determine the reference name to use for a new branch: |
| 132 | + |
| 133 | ------------ |
Junio C Hamano | ad70bf0 | 2016-09-26 23:44:27 | [diff] [blame] | 134 | $ 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 Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 136 | ------------ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 137 | |
| 138 | GIT |
| 139 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 140 | Part of the linkgit:git[1] suite |