6 gitprotocol-v2 - Git Wire Protocol, Version 2
11 <over-the-wire-protocol>
16 This document presents a specification for a version 2 of Git's wire
17 protocol. Protocol v2 will improve upon v1 in the following ways:
19 * Instead of multiple service names, multiple commands will be
20 supported by a single service
21 * Easily extendable as capabilities are moved into their own section
22 of the protocol, no longer being hidden behind a NUL byte and
23 limited by the size of a pkt-line
24 * Separate out other information hidden behind NUL bytes (e.g. agent
25 string as a capability and symrefs can be requested using 'ls-refs')
26 * Reference advertisement will be omitted unless explicitly requested
27 * ls-refs command to explicitly request some refs
28 * Designed with http and stateless-rpc in mind. With clear flush
29 semantics the http remote helper can simply act as a proxy
31 In protocol v2 communication is command oriented. When first contacting a
32 server a list of capabilities will advertised. Some of these capabilities
33 will be commands which a client can request be executed. Once a command
34 has completed, a client can reuse the connection and request that other
40 All communication is done using packet-line framing, just as in v1. See
41 linkgit:gitprotocol-pack[5] and linkgit:gitprotocol-common[5] for more information.
43 In protocol v2 these special packets will have the following semantics:
45 * '0000' Flush Packet (flush-pkt) - indicates the end of a message
46 * '0001' Delimiter Packet (delim-pkt) - separates sections of a message
47 * '0002' Response End Packet (response-end-pkt) - indicates the end of a
48 response for stateless connections
50 Initial Client Request
51 ----------------------
53 In general a client can request to speak protocol v2 by sending
54 `version=2` through the respective side-channel for the transport being
55 used which inevitably sets `GIT_PROTOCOL`. More information can be
56 found in linkgit:gitprotocol-pack[5] and linkgit:gitprotocol-http[5], as well as the
57 `GIT_PROTOCOL` definition in `git.txt`. In all cases the
58 response from the server is the capability advertisement.
63 When using the git:// transport, you can request to use protocol v2 by
64 sending "version=2" as an extra parameter:
66 003egit-upload-pack /project.git\0host=myserver.com\0\0version=2\0
68 SSH and File Transport
69 ~~~~~~~~~~~~~~~~~~~~~~
71 When using either the ssh:// or file:// transport, the GIT_PROTOCOL
72 environment variable must be set explicitly to include "version=2".
73 The server may need to be configured to allow this environment variable
79 When using the http:// or https:// transport a client makes a "smart"
80 info/refs request as described in linkgit:gitprotocol-http[5] and requests that
81 v2 be used by supplying "version=2" in the `Git-Protocol` header.
83 C: GET $GIT_URL/info/refs?service=git-upload-pack HTTP/1.0
84 C: Git-Protocol: version=2
86 A v2 server would reply:
93 S: <capability-advertisement>
95 Subsequent requests are then made directly to the service
96 `$GIT_URL/git-upload-pack`. (This works the same for git-receive-pack).
98 Uses the `--http-backend-info-refs` option to
99 linkgit:git-upload-pack[1].
101 The server may need to be configured to pass this header's contents via
102 the `GIT_PROTOCOL` variable. See the discussion in `git-http-backend.txt`.
104 Capability Advertisement
105 ------------------------
107 A server which decides to communicate (based on a request from a client)
108 using protocol version 2, notifies the client by sending a version string
109 in its initial response followed by an advertisement of its capabilities.
110 Each capability is a key with an optional value. Clients must ignore all
111 unknown keys. Semantics of unknown values are left to the definition of
112 each key. Some capabilities will describe commands which can be requested
113 to be executed by the client.
115 capability-advertisement = protocol-version
119 protocol-version = PKT-LINE("version 2" LF)
120 capability-list = *capability
121 capability = PKT-LINE(key[=value] LF)
123 key = 1*(ALPHA | DIGIT | "-_")
124 value = 1*(ALPHA | DIGIT | " -_.,?\/{}[]()<>!@#$%^&*+=:;")
129 After receiving the capability advertisement, a client can then issue a
130 request to select the command it wants with any particular capabilities
131 or arguments. There is then an optional section where the client can
132 provide any command specific parameters or queries. Only a single
133 command can be requested at a time.
135 request = empty-request | command-request
136 empty-request = flush-pkt
137 command-request = command
142 command = PKT-LINE("command=" key LF)
143 command-args = *command-specific-arg
145 command-specific-args are packet line framed arguments defined by
146 each individual command.
148 The server will then check to ensure that the client's request is
149 comprised of a valid command as well as valid capabilities which were
150 advertised. If the request is valid the server will then execute the
151 command. A server MUST wait till it has received the client's entire
152 request before issuing a response. The format of the response is
153 determined by the command being executed, but in all cases a flush-pkt
154 indicates the end of the response.
156 When a command has finished, and the client has received the entire
157 response from the server, a client can either request that another
158 command be executed or can terminate the connection. A client may
159 optionally send an empty request consisting of just a flush-pkt to
160 indicate that no more requests will be made.
165 There are two different types of capabilities: normal capabilities,
166 which can be used to convey information or alter the behavior of a
167 request, and commands, which are the core actions that a client wants to
168 perform (fetch, push, etc).
170 Protocol version 2 is stateless by default. This means that all commands
171 must only last a single round and be stateless from the perspective of the
172 server side, unless the client has requested a capability indicating that
173 state should be maintained by the server. Clients MUST NOT require state
174 management on the server side in order to function correctly. This
175 permits simple round-robin load-balancing on the server side, without
176 needing to worry about state management.
181 The server can advertise the `agent` capability with a value `X` (in the
182 form `agent=X`) to notify the client that the server is running version
183 `X`. The client may optionally send its own agent string by including
184 the `agent` capability with a value `Y` (in the form `agent=Y`) in its
185 request to the server (but it MUST NOT do so if the server did not
186 advertise the agent capability). The `X` and `Y` strings may contain any
187 printable ASCII characters except space (i.e., the byte range 32 < x <
188 127), and are typically of the form "package/version" (e.g.,
189 "git/1.8.3.1"). The agent strings are purely informative for statistics
190 and debugging purposes, and MUST NOT be used to programmatically assume
191 the presence or absence of particular features.
196 `ls-refs` is the command used to request a reference advertisement in v2.
197 Unlike the current reference advertisement, ls-refs takes in arguments
198 which can be used to limit the refs sent from the server.
200 Additional features not supported in the base command will be advertised
201 as the value of the command in the capability advertisement in the form
202 of a space separated list of features: "<command>=<feature 1> <feature 2>"
204 ls-refs takes in the following arguments:
207 In addition to the object pointed by it, show the underlying ref
208 pointed by it when showing a symbolic ref.
212 When specified, only references having a prefix matching one of
213 the provided prefixes are displayed. Multiple instances may be
214 given, in which case references matching any prefix will be
215 shown. Note that this is purely for optimization; a server MAY
216 show refs not matching the prefix if it chooses, and clients
217 should filter the result themselves.
219 If the 'unborn' feature is advertised the following argument can be
220 included in the client's request.
223 The server will send information about HEAD even if it is a symref
224 pointing to an unborn branch in the form "unborn HEAD
225 symref-target:<target>".
227 The output of ls-refs is as follows:
231 obj-id-or-unborn = (obj-id | "unborn")
232 ref = PKT-LINE(obj-id-or-unborn SP refname *(SP ref-attribute) LF)
233 ref-attribute = (symref | peeled)
234 symref = "symref-target:" symref-target
235 peeled = "peeled:" obj-id
240 `fetch` is the command used to fetch a packfile in v2. It can be looked
241 at as a modified version of the v1 fetch where the ref-advertisement is
242 stripped out (since the `ls-refs` command fills that role) and the
243 message format is tweaked to eliminate redundancies and permit easy
244 addition of future extensions.
246 Additional features not supported in the base command will be advertised
247 as the value of the command in the capability advertisement in the form
248 of a space separated list of features: "<command>=<feature 1> <feature 2>"
250 A `fetch` request can take the following arguments:
253 Indicates to the server an object which the client wants to
254 retrieve. Wants can be anything and are not limited to
258 Indicates to the server an object which the client has locally.
259 This allows the server to make a packfile which only contains
260 the objects that the client needs. Multiple 'have' lines can be
264 Indicates to the server that negotiation should terminate (or
265 not even begin if performing a clone) and that the server should
266 use the information supplied in the request to construct the
270 Request that a thin pack be sent, which is a pack with deltas
271 which reference base objects not contained within the pack (but
272 are known to exist at the receiving end). This can reduce the
273 network traffic significantly, but it requires the receiving end
274 to know how to "thicken" these packs by adding the missing bases
278 Request that progress information that would normally be sent on
279 side-band channel 2, during the packfile transfer, should not be
280 sent. However, the side-band channel 3 is still used for error
284 Request that annotated tags should be sent if the objects they
285 point to are being sent.
288 Indicate that the client understands PACKv2 with delta referring
289 to its base by position in pack rather than by an oid. That is,
290 they can read OBJ_OFS_DELTA (aka type 6) in a packfile.
292 If the 'shallow' feature is advertised the following arguments can be
293 included in the clients request as well as the potential addition of the
294 'shallow-info' section in the server's response as explained below.
297 A client must notify the server of all commits for which it only
298 has shallow copies (meaning that it doesn't have the parents of
299 a commit) by supplying a 'shallow <oid>' line for each such
300 object so that the server is aware of the limitations of the
301 client's history. This is so that the server is aware that the
302 client may not have all objects reachable from such commits.
305 Requests that the fetch/clone should be shallow having a commit
306 depth of <depth> relative to the remote side.
309 Requests that the semantics of the "deepen" command be changed
310 to indicate that the depth requested is relative to the client's
311 current shallow boundary, instead of relative to the requested
314 deepen-since <timestamp>
315 Requests that the shallow clone/fetch should be cut at a
316 specific time, instead of depth. Internally it's equivalent to
317 doing "git rev-list --max-age=<timestamp>". Cannot be used with
321 Requests that the shallow clone/fetch should be cut at a
322 specific revision specified by '<rev>', instead of a depth.
323 Internally it's equivalent of doing "git rev-list --not <rev>".
324 Cannot be used with "deepen", but can be used with
327 If the 'filter' feature is advertised, the following argument can be
328 included in the client's request:
331 Request that various objects from the packfile be omitted
332 using one of several filtering techniques. These are intended
333 for use with partial clone and partial fetch operations. See
334 `rev-list` for possible "filter-spec" values. When communicating
335 with other processes, senders SHOULD translate scaled integers
336 (e.g. "1k") into a fully-expanded form (e.g. "1024") to aid
337 interoperability with older receivers that may not understand
338 newly-invented scaling suffixes. However, receivers SHOULD
339 accept the following suffixes: 'k', 'm', and 'g' for 1024,
340 1048576, and 1073741824, respectively.
342 If the 'ref-in-want' feature is advertised, the following argument can
343 be included in the client's request as well as the potential addition of
344 the 'wanted-refs' section in the server's response as explained below.
347 Indicates to the server that the client wants to retrieve a
348 particular ref, where <ref> is the full name of a ref on the
351 If the 'sideband-all' feature is advertised, the following argument can be
352 included in the client's request:
355 Instruct the server to send the whole response multiplexed, not just
356 the packfile section. All non-flush and non-delim PKT-LINE in the
357 response (not only in the packfile section) will then start with a byte
358 indicating its sideband (1, 2, or 3), and the server may send "0005\2"
359 (a PKT-LINE of sideband 2 with no payload) as a keepalive packet.
361 If the 'packfile-uris' feature is advertised, the following argument
362 can be included in the client's request as well as the potential
363 addition of the 'packfile-uris' section in the server's response as
366 packfile-uris <comma-separated list of protocols>
367 Indicates to the server that the client is willing to receive
368 URIs of any of the given protocols in place of objects in the
369 sent packfile. Before performing the connectivity check, the
370 client should download from all given URIs. Currently, the
371 protocols supported are "http" and "https".
373 If the 'wait-for-done' feature is advertised, the following argument
374 can be included in the client's request.
377 Indicates to the server that it should never send "ready", but
378 should wait for the client to say "done" before sending the
381 The response of `fetch` is broken into a number of sections separated by
382 delimiter packets (0001), with each section beginning with its section
383 header. Most sections are sent only when the packfile is sent.
385 output = acknowledgements flush-pkt |
386 [acknowledgments delim-pkt] [shallow-info delim-pkt]
387 [wanted-refs delim-pkt] [packfile-uris delim-pkt]
390 acknowledgments = PKT-LINE("acknowledgments" LF)
393 ready = PKT-LINE("ready" LF)
394 nak = PKT-LINE("NAK" LF)
395 ack = PKT-LINE("ACK" SP obj-id LF)
397 shallow-info = PKT-LINE("shallow-info" LF)
398 *PKT-LINE((shallow | unshallow) LF)
399 shallow = "shallow" SP obj-id
400 unshallow = "unshallow" SP obj-id
402 wanted-refs = PKT-LINE("wanted-refs" LF)
403 *PKT-LINE(wanted-ref LF)
404 wanted-ref = obj-id SP refname
406 packfile-uris = PKT-LINE("packfile-uris" LF) *packfile-uri
407 packfile-uri = PKT-LINE(40*(HEXDIGIT) SP *%x20-ff LF)
409 packfile = PKT-LINE("packfile" LF)
410 *PKT-LINE(%x01-03 *%x00-ff)
412 acknowledgments section
413 * If the client determines that it is finished with negotiations by
414 sending a "done" line (thus requiring the server to send a packfile),
415 the acknowledgments sections MUST be omitted from the server's
418 * Always begins with the section header "acknowledgments"
420 * The server will respond with "NAK" if none of the object ids sent
421 as have lines were common.
423 * The server will respond with "ACK obj-id" for all of the
424 object ids sent as have lines which are common.
426 * A response cannot have both "ACK" lines as well as a "NAK"
429 * The server will respond with a "ready" line indicating that
430 the server has found an acceptable common base and is ready to
431 make and send a packfile (which will be found in the packfile
432 section of the same response)
434 * If the server has found a suitable cut point and has decided
435 to send a "ready" line, then the server can decide to (as an
436 optimization) omit any "ACK" lines it would have sent during
437 its response. This is because the server will have already
438 determined the objects it plans to send to the client and no
439 further negotiation is needed.
442 * If the client has requested a shallow fetch/clone, a shallow
443 client requests a fetch or the server is shallow then the
444 server's response may include a shallow-info section. The
445 shallow-info section will be included if (due to one of the
446 above conditions) the server needs to inform the client of any
447 shallow boundaries or adjustments to the clients already
448 existing shallow boundaries.
450 * Always begins with the section header "shallow-info"
452 * If a positive depth is requested, the server will compute the
453 set of commits which are no deeper than the desired depth.
455 * The server sends a "shallow obj-id" line for each commit whose
456 parents will not be sent in the following packfile.
458 * The server sends an "unshallow obj-id" line for each commit
459 which the client has indicated is shallow, but is no longer
460 shallow as a result of the fetch (due to its parents being
461 sent in the following packfile).
463 * The server MUST NOT send any "unshallow" lines for anything
464 which the client has not indicated was shallow as a part of
468 * This section is only included if the client has requested a
469 ref using a 'want-ref' line and if a packfile section is also
470 included in the response.
472 * Always begins with the section header "wanted-refs".
474 * The server will send a ref listing ("<oid> <refname>") for
475 each reference requested using 'want-ref' lines.
477 * The server MUST NOT send any refs which were not requested
478 using 'want-ref' lines.
480 packfile-uris section
481 * This section is only included if the client sent
482 'packfile-uris' and the server has at least one such URI to
485 * Always begins with the section header "packfile-uris".
487 * For each URI the server sends, it sends a hash of the pack's
488 contents (as output by git index-pack) followed by the URI.
490 * The hashes are 40 hex characters long. When Git upgrades to a new
491 hash algorithm, this might need to be updated. (It should match
492 whatever index-pack outputs after "pack\t" or "keep\t".
495 * This section is only included if the client has sent 'want'
496 lines in its request and either requested that no more
497 negotiation be done by sending 'done' or if the server has
498 decided it has found a sufficient cut point to produce a
501 * Always begins with the section header "packfile"
503 * The transmission of the packfile begins immediately after the
506 * The data transfer of the packfile is always multiplexed, using
507 the same semantics of the 'side-band-64k' capability from
508 protocol version 1. This means that each packet, during the
509 packfile data stream, is made up of a leading 4-byte pkt-line
510 length (typical of the pkt-line format), followed by a 1-byte
511 stream code, followed by the actual data.
513 The stream code can be one of:
515 2 - progress messages
516 3 - fatal error message just before stream aborts
521 If advertised, indicates that any number of server specific options can be
522 included in a request. This is done by sending each option as a
523 "server-option=<option>" capability line in the capability-list section of
526 The provided options must not contain a NUL or LF character.
531 The server can advertise the `object-format` capability with a value `X` (in the
532 form `object-format=X`) to notify the client that the server is able to deal
533 with objects using hash algorithm X. If not specified, the server is assumed to
534 only handle SHA-1. If the client would like to use a hash algorithm other than
535 SHA-1, it should specify its object-format string.
537 session-id=<session id>
538 ~~~~~~~~~~~~~~~~~~~~~~~
540 The server may advertise a session ID that can be used to identify this process
541 across multiple requests. The client may advertise its own session ID back to
544 Session IDs should be unique to a given process. They must fit within a
545 packet-line, and must not contain non-printable or whitespace characters. The
546 current implementation uses trace2 session IDs (see
547 link:technical/api-trace2.html[api-trace2] for details), but this may change
548 and users of the session ID should not rely on this fact.
553 `object-info` is the command to retrieve information about one or more objects.
554 Its main purpose is to allow a client to make decisions based on this
555 information without having to fully fetch objects. Object size is the only
556 information that is currently supported.
558 An `object-info` request takes the following arguments:
561 Requests size information to be returned for each listed object id.
564 Indicates to the server an object which the client wants to obtain
567 The response of `object-info` is a list of the requested object ids
568 and associated requested information, each separated by a single space.
570 output = info flush-pkt
572 info = PKT-LINE(attrs) LF)
573 *PKT-LINE(obj-info LF)
575 attrs = attr | attrs SP attrs
579 obj-info = obj-id SP obj-size
583 Part of the linkgit:git[1] suite