Documentation / git-check-ref-format.txton commit Merge branch 'mz/oneway-merge-wo-u-no-lstat' (2d0029e)
   1git-check-ref-format(1)
   2=======================
   3
   4NAME
   5----
   6git-check-ref-format - Ensures that a reference name is well formed
   7
   8SYNOPSIS
   9--------
  10[verse]
  11'git check-ref-format' [--normalize]
  12       [--[no-]allow-onelevel] [--refspec-pattern]
  13       <refname>
  14'git check-ref-format' --branch <branchname-shorthand>
  15
  16DESCRIPTION
  17-----------
  18Checks if a given 'refname' is acceptable, and exits with a non-zero
  19status if it is not.
  20
  21A reference is used in git to specify branches and tags.  A
  22branch 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
  28git imposes the following rules on how references are named:
  29
  30. They can include slash `/` for hierarchical (directory)
  31  grouping, but no slash-separated component can begin with a
  32  dot `.` or end with the sequence `.lock`.
  33
  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
  36  restricted.  If the `--allow-onelevel` option is used, this rule
  37  is waived.
  38
  39. They cannot have two consecutive dots `..` anywhere.
  40
  41. They cannot have ASCII control characters (i.e. bytes whose
  42  values are lower than \040, or \177 `DEL`), space, tilde `~`,
  43  caret `^`, or colon `:` anywhere.
  44
  45. They cannot have question-mark `?`, asterisk `*`, or open
  46  bracket `[` anywhere.  See the `--refspec-pattern` option below for
  47  an exception to this rule.
  48
  49. 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 `.`.
  54
  55. They cannot contain a sequence `@{`.
  56
  57. They cannot contain a `\`.
  58
  59These rules make it easy for shell script based tools to parse
  60reference names, pathname expansion by the shell when a reference name is used
  61unquoted (by mistake), and also avoids ambiguities in certain
  62reference name expressions (see linkgit:gitrevisions[7]):
  63
  64. A double-dot `..` is often used as in `ref1..ref2`, and in some
  65  contexts this notation means `^ref1 ref2` (i.e. not in
  66  `ref1` and in `ref2`).
  67
  68. A tilde `~` and caret `^` are used to introduce the postfix
  69  'nth parent' and 'peel onion' operation.
  70
  71. A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s
  72  value and store it in dstref" in fetch and push operations.
  73  It may also be used to select a specific object such as with
  74  'git cat-file': "git cat-file blob v1.3.3:refs.c".
  75
  76. at-open-brace `@{` is used as a notation to access a reflog entry.
  77
  78With 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.
  83
  84OPTIONS
  85-------
  86--allow-onelevel::
  87--no-allow-onelevel::
  88        Controls whether one-level refnames are accepted (i.e.,
  89        refnames that do not contain multiple `/`-separated
  90        components).  The default is `--no-allow-onelevel`.
  91
  92--refspec-pattern::
  93        Interpret <refname> as a reference name pattern for a refspec
  94        (as used with remote repositories).  If this option is
  95        enabled, <refname> is allowed to contain a single `*`
  96        in place of a one full pathname component (e.g.,
  97        `foo/*/bar` but not `foo/bar*`).
  98
  99--normalize::
 100        Normalize 'refname' by removing any leading slash (`/`)
 101        characters and collapsing runs of adjacent slashes between
 102        name components into a single slash.  Iff the normalized
 103        refname is valid then print it to standard output and exit
 104        with a status of 0.  (`--print` is a deprecated way to spell
 105        `--normalize`.)
 106
 107
 108EXAMPLES
 109--------
 110
 111* Print the name of the previous branch:
 112+
 113------------
 114$ git check-ref-format --branch @{-1}
 115------------
 116
 117* Determine the reference name to use for a new branch:
 118+
 119------------
 120$ ref=$(git check-ref-format --normalize "refs/heads/$newbranch") ||
 121die "we do not like '$newbranch' as a branch name."
 122------------
 123
 124GIT
 125---
 126Part of the linkgit:git[1] suite