NAME

git-update-ref - Update the object name stored in a ref safely

SYNOPSIS

  1. git update-ref [-m <reason>] [--no-deref] (-d <ref> [<oldvalue>] | [--create-reflog] <ref> <newvalue> [<oldvalue>] | --stdin [-z])

DESCRIPTION

Given two arguments, stores the <newvalue> in the <ref>, possiblydereferencing the symbolic refs. E.g. git update-ref HEAD<newvalue> updates the current branch head to the new object.

Given three arguments, stores the <newvalue> in the <ref>,possibly dereferencing the symbolic refs, after verifying thatthe current value of the <ref> matches <oldvalue>.E.g. git update-ref refs/heads/master <newvalue> <oldvalue>updates the master branch head to <newvalue> only if its currentvalue is <oldvalue>. You can specify 40 "0" or an empty stringas <oldvalue> to make sure that the ref you are creating doesnot exist.

It also allows a "ref" file to be a symbolic pointer to anotherref file by starting with the four-byte header sequence of"ref:".

More importantly, it allows the update of a ref file to followthese symbolic pointers, whether they are symlinks or these"regular file symbolic refs". It follows real symlinks onlyif they start with "refs/": otherwise it will just try to readthem and update them as a regular file (i.e. it will allow thefilesystem to follow them, but will overwrite such a symlink tosomewhere else with a regular filename).

If —no-deref is given, <ref> itself is overwritten, rather thanthe result of following the symbolic pointers.

In general, using

  1. git update-ref HEAD "$head"

should be a lot safer than doing

  1. echo "$head" > "$GIT_DIR/HEAD"

both from a symlink following standpoint and an error checkingstandpoint. The "refs/" rule for symlinks means that symlinksthat point to "outside" the tree are safe: they’ll be followedfor reading but not for writing (so we’ll never write through aref symlink to some other tree, if you have copied a wholearchive by creating a symlink tree).

With -d flag, it deletes the named <ref> after verifying itstill contains <oldvalue>.

With —stdin, update-ref reads instructions from standard input andperforms all modifications together. Specify commands of the form:

  1. update SP <ref> SP <newvalue> [SP <oldvalue>] LF
  2. create SP <ref> SP <newvalue> LF
  3. delete SP <ref> [SP <oldvalue>] LF
  4. verify SP <ref> [SP <oldvalue>] LF
  5. option SP <opt> LF

With —create-reflog, update-ref will create a reflog for each refeven if one would not ordinarily be created.

Quote fields containing whitespace as if they were strings in C sourcecode; i.e., surrounded by double-quotes and with backslash escapes.Use 40 "0" characters or the empty string to specify a zero value. Tospecify a missing value, omit the value and its preceding SP entirely.

Alternatively, use -z to specify in NUL-terminated format, withoutquoting:

  1. update SP <ref> NUL <newvalue> NUL [<oldvalue>] NUL
  2. create SP <ref> NUL <newvalue> NUL
  3. delete SP <ref> NUL [<oldvalue>] NUL
  4. verify SP <ref> NUL [<oldvalue>] NUL
  5. option SP <opt> NUL

In this format, use 40 "0" to specify a zero value, and use the emptystring to specify a missing value.

In either format, values can be specified in any form that Gitrecognizes as an object name. Commands in any other format or arepeated <ref> produce an error. Command meanings are:

  • update
  • Set to after verifying , if given.Specify a zero to ensure the ref does not existafter the update and/or a zero to make sure theref does not exist before the update.

  • create

  • Create with after verifying it does notexist. The given may not be zero.

  • delete

  • Delete after verifying it exists with , ifgiven. If given, may not be zero.

  • verify

  • Verify against but do not change it. If zero or missing, the ref must not exist.

  • option

  • Modify behavior of the next command naming a .The only valid option is no-deref to avoid dereferencinga symbolic ref.

If all <ref>s can be locked with matching <oldvalue>ssimultaneously, all modifications are performed. Otherwise, nomodifications are performed. Note that while each individual<ref> is updated or deleted atomically, a concurrent reader maystill see a subset of the modifications.

LOGGING UPDATES

If config parameter "core.logAllRefUpdates" is true and the ref is one under"refs/heads/", "refs/remotes/", "refs/notes/", or the symbolic ref HEAD; orthe file "$GIT_DIR/logs/<ref>" exists then git update-ref will appenda line to the log file "$GIT_DIR/logs/<ref>" (dereferencing allsymbolic refs before creating the log name) describing the changein ref value. Log lines are formatted as:

  1. oldsha1 SP newsha1 SP committer LF

Where "oldsha1" is the 40 character hexadecimal value previouslystored in <ref>, "newsha1" is the 40 character hexadecimal value of<newvalue> and "committer" is the committer’s name, email addressand date in the standard Git committer ident format.

Optionally with -m:

  1. oldsha1 SP newsha1 SP committer TAB message LF

Where all fields are as described above and "message" is thevalue supplied to the -m option.

An update will fail (without changing <ref>) if the current user isunable to create a new log file, append to the existing log fileor does not have committer information available.

GIT

Part of the git[1] suite