1GIT-UPDATE-REF(1)                 Git Manual                 GIT-UPDATE-REF(1)
2
3
4

NAME

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

SYNOPSIS

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

DESCRIPTION

12       Given two arguments, stores the <newvalue> in the <ref>, possibly
13       dereferencing the symbolic refs. E.g. git update-ref HEAD <newvalue>
14       updates the current branch head to the new object.
15
16       Given three arguments, stores the <newvalue> in the <ref>, possibly
17       dereferencing the symbolic refs, after verifying that the current value
18       of the <ref> matches <oldvalue>. E.g. git update-ref refs/heads/master
19       <newvalue> <oldvalue> updates the master branch head to <newvalue> only
20       if its current value is <oldvalue>. You can specify 40 "0" or an empty
21       string as <oldvalue> to make sure that the ref you are creating does
22       not exist.
23
24       It also allows a "ref" file to be a symbolic pointer to another ref
25       file by starting with the four-byte header sequence of "ref:".
26
27       More importantly, it allows the update of a ref file to follow these
28       symbolic pointers, whether they are symlinks or these "regular file
29       symbolic refs". It follows real symlinks only if they start with
30       "refs/": otherwise it will just try to read them and update them as a
31       regular file (i.e. it will allow the filesystem to follow them, but
32       will overwrite such a symlink to somewhere else with a regular
33       filename).
34
35       If --no-deref is given, <ref> itself is overwritten, rather than the
36       result of following the symbolic pointers.
37
38       In general, using
39
40           git update-ref HEAD "$head"
41
42       should be a lot safer than doing
43
44           echo "$head" > "$GIT_DIR/HEAD"
45
46       both from a symlink following standpoint and an error checking
47       standpoint. The "refs/" rule for symlinks means that symlinks that
48       point to "outside" the tree are safe: they’ll be followed for reading
49       but not for writing (so we’ll never write through a ref symlink to some
50       other tree, if you have copied a whole archive by creating a symlink
51       tree).
52
53       With -d flag, it deletes the named <ref> after verifying it still
54       contains <oldvalue>.
55
56       With --stdin, update-ref reads instructions from standard input and
57       performs all modifications together. Specify commands of the form:
58
59           update SP <ref> SP <newvalue> [SP <oldvalue>] LF
60           create SP <ref> SP <newvalue> LF
61           delete SP <ref> [SP <oldvalue>] LF
62           verify SP <ref> [SP <oldvalue>] LF
63           option SP <opt> LF
64
65       With --create-reflog, update-ref will create a reflog for each ref even
66       if one would not ordinarily be created.
67
68       Quote fields containing whitespace as if they were strings in C source
69       code; i.e., surrounded by double-quotes and with backslash escapes. Use
70       40 "0" characters or the empty string to specify a zero value. To
71       specify a missing value, omit the value and its preceding SP entirely.
72
73       Alternatively, use -z to specify in NUL-terminated format, without
74       quoting:
75
76           update SP <ref> NUL <newvalue> NUL [<oldvalue>] NUL
77           create SP <ref> NUL <newvalue> NUL
78           delete SP <ref> NUL [<oldvalue>] NUL
79           verify SP <ref> NUL [<oldvalue>] NUL
80           option SP <opt> NUL
81
82       In this format, use 40 "0" to specify a zero value, and use the empty
83       string to specify a missing value.
84
85       In either format, values can be specified in any form that Git
86       recognizes as an object name. Commands in any other format or a
87       repeated <ref> produce an error. Command meanings are:
88
89       update
90           Set <ref> to <newvalue> after verifying <oldvalue>, if given.
91           Specify a zero <newvalue> to ensure the ref does not exist after
92           the update and/or a zero <oldvalue> to make sure the ref does not
93           exist before the update.
94
95       create
96           Create <ref> with <newvalue> after verifying it does not exist. The
97           given <newvalue> may not be zero.
98
99       delete
100           Delete <ref> after verifying it exists with <oldvalue>, if given.
101           If given, <oldvalue> may not be zero.
102
103       verify
104           Verify <ref> against <oldvalue> but do not change it. If <oldvalue>
105           zero or missing, the ref must not exist.
106
107       option
108           Modify behavior of the next command naming a <ref>. The only valid
109           option is no-deref to avoid dereferencing a symbolic ref.
110
111       If all <ref>s can be locked with matching <oldvalue>s simultaneously,
112       all modifications are performed. Otherwise, no modifications are
113       performed. Note that while each individual <ref> is updated or deleted
114       atomically, a concurrent reader may still see a subset of the
115       modifications.
116

LOGGING UPDATES

118       If config parameter "core.logAllRefUpdates" is true and the ref is one
119       under "refs/heads/", "refs/remotes/", "refs/notes/", or the symbolic
120       ref HEAD; or the file "$GIT_DIR/logs/<ref>" exists then git update-ref
121       will append a line to the log file "$GIT_DIR/logs/<ref>" (dereferencing
122       all symbolic refs before creating the log name) describing the change
123       in ref value. Log lines are formatted as:
124
125           oldsha1 SP newsha1 SP committer LF
126
127       Where "oldsha1" is the 40 character hexadecimal value previously stored
128       in <ref>, "newsha1" is the 40 character hexadecimal value of <newvalue>
129       and "committer" is the committer’s name, email address and date in the
130       standard Git committer ident format.
131
132       Optionally with -m:
133
134           oldsha1 SP newsha1 SP committer TAB message LF
135
136       Where all fields are as described above and "message" is the value
137       supplied to the -m option.
138
139       An update will fail (without changing <ref>) if the current user is
140       unable to create a new log file, append to the existing log file or
141       does not have committer information available.
142

GIT

144       Part of the git(1) suite
145
146
147
148Git 2.26.2                        2020-04-20                 GIT-UPDATE-REF(1)
Impressum