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