Documentation / git-update-ref.txton commit Update draft release notes to 1.9 (d7aced9)
   1git-update-ref(1)
   2=================
   3
   4NAME
   5----
   6git-update-ref - Update the object name stored in a ref safely
   7
   8SYNOPSIS
   9--------
  10[verse]
  11'git update-ref' [-m <reason>] (-d <ref> [<oldvalue>] | [--no-deref] <ref> <newvalue> [<oldvalue>] | --stdin [-z])
  12
  13DESCRIPTION
  14-----------
  15Given two arguments, stores the <newvalue> in the <ref>, possibly
  16dereferencing the symbolic refs.  E.g. `git update-ref HEAD
  17<newvalue>` updates the current branch head to the new object.
  18
  19Given three arguments, stores the <newvalue> in the <ref>,
  20possibly dereferencing the symbolic refs, after verifying that
  21the current value of the <ref> matches <oldvalue>.
  22E.g. `git update-ref refs/heads/master <newvalue> <oldvalue>`
  23updates the master branch head to <newvalue> only if its current
  24value is <oldvalue>.  You can specify 40 "0" or an empty string
  25as <oldvalue> to make sure that the ref you are creating does
  26not exist.
  27
  28It also allows a "ref" file to be a symbolic pointer to another
  29ref file by starting with the four-byte header sequence of
  30"ref:".
  31
  32More importantly, it allows the update of a ref file to follow
  33these symbolic pointers, whether they are symlinks or these
  34"regular file symbolic refs".  It follows *real* symlinks only
  35if they start with "refs/": otherwise it will just try to read
  36them and update them as a regular file (i.e. it will allow the
  37filesystem to follow them, but will overwrite such a symlink to
  38somewhere else with a regular filename).
  39
  40If --no-deref is given, <ref> itself is overwritten, rather than
  41the result of following the symbolic pointers.
  42
  43In general, using
  44
  45        git update-ref HEAD "$head"
  46
  47should be a _lot_ safer than doing
  48
  49        echo "$head" > "$GIT_DIR/HEAD"
  50
  51both from a symlink following standpoint *and* an error checking
  52standpoint.  The "refs/" rule for symlinks means that symlinks
  53that point to "outside" the tree are safe: they'll be followed
  54for reading but not for writing (so we'll never write through a
  55ref symlink to some other tree, if you have copied a whole
  56archive by creating a symlink tree).
  57
  58With `-d` flag, it deletes the named <ref> after verifying it
  59still contains <oldvalue>.
  60
  61With `--stdin`, update-ref reads instructions from standard input and
  62performs all modifications together.  Specify commands of the form:
  63
  64        update SP <ref> SP <newvalue> [SP <oldvalue>] LF
  65        create SP <ref> SP <newvalue> LF
  66        delete SP <ref> [SP <oldvalue>] LF
  67        verify SP <ref> [SP <oldvalue>] LF
  68        option SP <opt> LF
  69
  70Quote fields containing whitespace as if they were strings in C source
  71code.  Alternatively, use `-z` to specify commands without quoting:
  72
  73        update SP <ref> NUL <newvalue> NUL [<oldvalue>] NUL
  74        create SP <ref> NUL <newvalue> NUL
  75        delete SP <ref> NUL [<oldvalue>] NUL
  76        verify SP <ref> NUL [<oldvalue>] NUL
  77        option SP <opt> NUL
  78
  79Lines of any other format or a repeated <ref> produce an error.
  80Command meanings are:
  81
  82update::
  83        Set <ref> to <newvalue> after verifying <oldvalue>, if given.
  84        Specify a zero <newvalue> to ensure the ref does not exist
  85        after the update and/or a zero <oldvalue> to make sure the
  86        ref does not exist before the update.
  87
  88create::
  89        Create <ref> with <newvalue> after verifying it does not
  90        exist.  The given <newvalue> may not be zero.
  91
  92delete::
  93        Delete <ref> after verifying it exists with <oldvalue>, if
  94        given.  If given, <oldvalue> may not be zero.
  95
  96verify::
  97        Verify <ref> against <oldvalue> but do not change it.  If
  98        <oldvalue> zero or missing, the ref must not exist.
  99
 100option::
 101        Modify behavior of the next command naming a <ref>.
 102        The only valid option is `no-deref` to avoid dereferencing
 103        a symbolic ref.
 104
 105Use 40 "0" or the empty string to specify a zero value, except that
 106with `-z` an empty <oldvalue> is considered missing.
 107
 108If all <ref>s can be locked with matching <oldvalue>s
 109simultaneously, all modifications are performed.  Otherwise, no
 110modifications are performed.  Note that while each individual
 111<ref> is updated or deleted atomically, a concurrent reader may
 112still see a subset of the modifications.
 113
 114Logging Updates
 115---------------
 116If config parameter "core.logAllRefUpdates" is true and the ref is one under
 117"refs/heads/", "refs/remotes/", "refs/notes/", or the symbolic ref HEAD; or
 118the file "$GIT_DIR/logs/<ref>" exists then `git update-ref` will append
 119a line to the log file "$GIT_DIR/logs/<ref>" (dereferencing all
 120symbolic refs before creating the log name) describing the change
 121in ref value.  Log lines are formatted as:
 122
 123    . oldsha1 SP newsha1 SP committer LF
 124+
 125Where "oldsha1" is the 40 character hexadecimal value previously
 126stored in <ref>, "newsha1" is the 40 character hexadecimal value of
 127<newvalue> and "committer" is the committer's name, email address
 128and date in the standard Git committer ident format.
 129
 130Optionally with -m:
 131
 132    . oldsha1 SP newsha1 SP committer TAB message LF
 133+
 134Where all fields are as described above and "message" is the
 135value supplied to the -m option.
 136
 137An update will fail (without changing <ref>) if the current user is
 138unable to create a new log file, append to the existing log file
 139or does not have committer information available.
 140
 141GIT
 142---
 143Part of the linkgit:git[1] suite