summaryrefslogtreecommitdiff
path: root/devdocs/git/git-check-ref-format.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/git/git-check-ref-format.html
new repository
Diffstat (limited to 'devdocs/git/git-check-ref-format.html')
-rw-r--r--devdocs/git/git-check-ref-format.html10
1 files changed, 10 insertions, 0 deletions
diff --git a/devdocs/git/git-check-ref-format.html b/devdocs/git/git-check-ref-format.html
new file mode 100644
index 00000000..713418ee
--- /dev/null
+++ b/devdocs/git/git-check-ref-format.html
@@ -0,0 +1,10 @@
+<h1>git-check-ref-format</h1> <h2 id="_name">Name</h2> <div class="sectionbody"> <p>git-check-ref-format - Ensures that a reference name is well formed</p> </div> <h2 id="_synopsis">Synopsis</h2> <div class="sectionbody"> <div class="verseblock"> <pre class="content" data-language="shell">git check-ref-format [--normalize]
+ [--[no-]allow-onelevel] [--refspec-pattern]
+ &lt;refname&gt;
+git check-ref-format --branch &lt;branchname-shorthand&gt;</pre> </div> </div> <h2 id="_description">Description</h2> <div class="sectionbody"> <p>Checks if a given <code>refname</code> is acceptable, and exits with a non-zero status if it is not.</p> <p>A reference is used in Git to specify branches and tags. A branch head is stored in the <code>refs/heads</code> hierarchy, while a tag is stored in the <code>refs/tags</code> hierarchy of the ref namespace (typically in <code>$GIT_DIR/refs/heads</code> and <code>$GIT_DIR/refs/tags</code> directories or, as entries in file <code>$GIT_DIR/packed-refs</code> if refs are packed by <code>git gc</code>).</p> <p>Git imposes the following rules on how references are named:</p> <div class="olist arabic"> <ol class="arabic"> <li> <p>They can include slash <code>/</code> for hierarchical (directory) grouping, but no slash-separated component can begin with a dot <code>.</code> or end with the sequence <code>.lock</code>.</p> </li> <li> <p>They must contain at least one <code>/</code>. This enforces the presence of a category like <code>heads/</code>, <code>tags/</code> etc. but the actual names are not restricted. If the <code>--allow-onelevel</code> option is used, this rule is waived.</p> </li> <li> <p>They cannot have two consecutive dots <code>..</code> anywhere.</p> </li> <li> <p>They cannot have ASCII control characters (i.e. bytes whose values are lower than \040, or \177 <code>DEL</code>), space, tilde <code>~</code>, caret <code>^</code>, or colon <code>:</code> anywhere.</p> </li> <li> <p>They cannot have question-mark <code>?</code>, asterisk <code>*</code>, or open bracket <code>[</code> anywhere. See the <code>--refspec-pattern</code> option below for an exception to this rule.</p> </li> <li> <p>They cannot begin or end with a slash <code>/</code> or contain multiple consecutive slashes (see the <code>--normalize</code> option below for an exception to this rule).</p> </li> <li> <p>They cannot end with a dot <code>.</code>.</p> </li> <li> <p>They cannot contain a sequence <code>@{</code>.</p> </li> <li> <p>They cannot be the single character <code>@</code>.</p> </li> <li> <p>They cannot contain a <code>\</code>.</p> </li> </ol> </div> <p>These rules make it easy for shell script based tools to parse reference names, pathname expansion by the shell when a reference name is used unquoted (by mistake), and also avoid ambiguities in certain reference name expressions (see <a href="gitrevisions">gitrevisions[7]</a>):</p> <div class="olist arabic"> <ol class="arabic"> <li> <p>A double-dot <code>..</code> is often used as in <code>ref1..ref2</code>, and in some contexts this notation means <code>^ref1 ref2</code> (i.e. not in <code>ref1</code> and in <code>ref2</code>).</p> </li> <li> <p>A tilde <code>~</code> and caret <code>^</code> are used to introduce the postfix <code>nth parent</code> and <code>peel onion</code> operation.</p> </li> <li> <p>A colon <code>:</code> is used as in <code>srcref:dstref</code> to mean "use srcref’s value and store it in dstref" in fetch and push operations. It may also be used to select a specific object such as with 'git cat-file': "git cat-file blob v1.3.3:refs.c".</p> </li> <li> <p>at-open-brace <code>@{</code> is used as a notation to access a reflog entry.</p> </li> </ol> </div> <p>With the <code>--branch</code> option, the command takes a name and checks if it can be used as a valid branch name (e.g. when creating a new branch). But be cautious when using the previous checkout syntax that may refer to a detached HEAD state. The rule <code>git check-ref-format --branch $name</code> implements may be stricter than what <code>git check-ref-format refs/heads/$name</code> says (e.g. a dash may appear at the beginning of a ref component, but it is explicitly forbidden at the beginning of a branch name). When run with the <code>--branch</code> option in a repository, the input is first expanded for the “previous checkout syntax” <code>@{-n}</code>. For example, <code>@{-1}</code> is a way to refer the last thing that was checked out using "git switch" or "git checkout" operation. This option should be used by porcelains to accept this syntax anywhere a branch name is expected, so they can act as if you typed the branch name. As an exception note that, the “previous checkout operation” might result in a commit object name when the N-th last thing checked out was not a branch.</p> </div> <h2 id="_options">Options</h2> <div class="sectionbody"> <div class="dlist"> <dl> <dt class="hdlist1" id="Documentation/git-check-ref-format.txt---no-allow-onelevel"> --[no-]allow-onelevel </dt> <dd> <p>Controls whether one-level refnames are accepted (i.e., refnames that do not contain multiple <code>/</code>-separated components). The default is <code>--no-allow-onelevel</code>.</p> </dd> <dt class="hdlist1" id="Documentation/git-check-ref-format.txt---refspec-pattern"> --refspec-pattern </dt> <dd> <p>Interpret &lt;refname&gt; as a reference name pattern for a refspec (as used with remote repositories). If this option is enabled, &lt;refname&gt; is allowed to contain a single <code>*</code> in the refspec (e.g., <code>foo/bar*/baz</code> or <code>foo/bar*baz/</code> but not <code>foo/bar*/baz*</code>).</p> </dd> <dt class="hdlist1" id="Documentation/git-check-ref-format.txt---normalize"> --normalize </dt> <dd> <p>Normalize <code>refname</code> by removing any leading slash (<code>/</code>) characters and collapsing runs of adjacent slashes between name components into a single slash. If the normalized refname is valid then print it to standard output and exit with a status of 0, otherwise exit with a non-zero status. (<code>--print</code> is a deprecated way to spell <code>--normalize</code>.)</p> </dd> </dl> </div> </div> <h2 id="_examples">Examples</h2> <div class="sectionbody"> <div class="ulist"> <ul> <li> <p>Print the name of the previous thing checked out:</p> <div class="listingblock"> <div class="content"> <pre data-language="shell-session">$ git check-ref-format --branch @{-1}</pre> </div> </div> </li> <li> <p>Determine the reference name to use for a new branch:</p> <div class="listingblock"> <div class="content"> <pre data-language="shell-session">$ ref=$(git check-ref-format --normalize "refs/heads/$newbranch")||
+{ echo "we do not like '$newbranch' as a branch name." &gt;&amp;2 ; exit 1 ; }</pre> </div> </div> </li> </ul> </div> </div><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2012&ndash;2024 Scott Chacon and others<br>Licensed under the MIT License.<br>
+ <a href="https://git-scm.com/docs/git-check-ref-format" class="_attribution-link">https://git-scm.com/docs/git-check-ref-format</a>
+ </p>
+</div>