Documentation / git-check-ref-format.txton commit Merge branch 'rj/maint-cygwin-count-objects' (ba2c747)
   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' <refname>
  12'git check-ref-format' --print <refname>
  13'git check-ref-format' --branch <branchname-shorthand>
  14
  15DESCRIPTION
  16-----------
  17Checks if a given 'refname' is acceptable, and exits with a non-zero
  18status if it is not.
  19
  20A reference is used in git to specify branches and tags.  A
  21branch head is stored under the `$GIT_DIR/refs/heads` directory, and
  22a tag is stored under the `$GIT_DIR/refs/tags` directory.  git
  23imposes the following rules on how references are named:
  24
  25. They can include slash `/` for hierarchical (directory)
  26  grouping, but no slash-separated component can begin with a
  27  dot `.`.
  28
  29. They must contain at least one `/`. This enforces the presence of a
  30  category like `heads/`, `tags/` etc. but the actual names are not
  31  restricted.
  32
  33. They cannot have two consecutive dots `..` anywhere.
  34
  35. They cannot have ASCII control characters (i.e. bytes whose
  36  values are lower than \040, or \177 `DEL`), space, tilde `~`,
  37  caret `{caret}`, colon `:`, question-mark `?`, asterisk `*`,
  38  or open bracket `[` anywhere.
  39
  40. They cannot end with a slash `/` nor a dot `.`.
  41
  42. They cannot end with the sequence `.lock`.
  43
  44. They cannot contain a sequence `@{`.
  45
  46- They cannot contain a `\\`.
  47
  48These rules make it easy for shell script based tools to parse
  49reference names, pathname expansion by the shell when a reference name is used
  50unquoted (by mistake), and also avoids ambiguities in certain
  51reference name expressions (see linkgit:git-rev-parse[1]):
  52
  53. A double-dot `..` is often used as in `ref1..ref2`, and in some
  54  contexts this notation means `{caret}ref1 ref2` (i.e. not in
  55  `ref1` and in `ref2`).
  56
  57. A tilde `~` and caret `{caret}` are used to introduce the postfix
  58  'nth parent' and 'peel onion' operation.
  59
  60. A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s
  61  value and store it in dstref" in fetch and push operations.
  62  It may also be used to select a specific object such as with
  63  'git-cat-file': "git cat-file blob v1.3.3:refs.c".
  64
  65. at-open-brace `@{` is used as a notation to access a reflog entry.
  66
  67With the `--print` option, if 'refname' is acceptable, it prints the
  68canonicalized name of a hypothetical reference with that name.  That is,
  69it prints 'refname' with any extra `/` characters removed.
  70
  71With the `--branch` option, it expands the ``previous branch syntax''
  72`@{-n}`.  For example, `@{-1}` is a way to refer the last branch you
  73were on.  This option should be used by porcelains to accept this
  74syntax anywhere a branch name is expected, so they can act as if you
  75typed the branch name.
  76
  77EXAMPLES
  78--------
  79
  80* Print the name of the previous branch:
  81+
  82------------
  83$ git check-ref-format --branch @{-1}
  84------------
  85
  86* Determine the reference name to use for a new branch:
  87+
  88------------
  89$ ref=$(git check-ref-format --print "refs/heads/$newbranch") ||
  90die "we do not like '$newbranch' as a branch name."
  91------------
  92
  93GIT
  94---
  95Part of the linkgit:git[1] suite