2
0

protocol.txt 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. .. _protocol:
  2. ===================
  3. Git Server Protocol
  4. ===================
  5. Transport
  6. =========
  7. The Git protocol operates over pipes or TCP/IP. When a client connects over
  8. TCP/IP, it sends a header that tells the server which program to run and what
  9. parameters to use. When invoked over SSH, git will run a program with the
  10. parameters as command line arguments.
  11. Protocols
  12. =========
  13. Basics
  14. ------
  15. Git communicates with a server by piping data between a local program and a
  16. remote program.
  17. A common way of sending a unit of information is a pkt_line. This is a 4 byte
  18. size as human encoded hex (i.e. totally underusing the 4 bytes...) that tells
  19. you the size of the payload, followed by the payload. The size includes the 4
  20. bytes used by the size itself.
  21. 0009ABCD\n
  22. Git can also multiplex data using the sideband. As well as 4 bytes size, there
  23. would be a 1 byte channel number. This is in binary, so ``1`` will be ``\x01``.
  24. Typically Git will piggyback a list of capabilities on the first pkt_line it
  25. sends. It will also look for capabilities in the first pkt_like it receives.
  26. Git will degrade as much as possible when encountering a server or client with
  27. differing capabilities.
  28. git-upload-pack
  29. ---------------
  30. git-upload pack is used by git-ls-remote, git-clone, git-fetch and git-pull.
  31. And i'm sure others. Typically a client will connect a local git-fetch-pack to
  32. a remote git-upload-pack.
  33. Capabilities for this protocol include multi_ack, thin-pack, ofs-delta,
  34. sideband and sideband-64k A thin pack can reference objects not in the current
  35. pack.
  36. The server tells the client what refs it has. The client states which of those
  37. SHA1's it would like. It then starts to report which SHA1's it has. The server
  38. ACKs these allowing the client to work out when to stop sending SHA1's. This
  39. saves a lot of transfer because the client can make decisions like "well if it
  40. has this SHA, then it has all its parents so I don't need to care about those".
  41. When the client stops sending shas, the server can work out an optimal pack and
  42. then send it to the client.
  43. git-receive-pack
  44. ----------------
  45. git-receive-pack is used by git push. Typically a client connects a local
  46. git-send-pack to a remote git-receive-pack.
  47. Capabilities include report-status and delete-ref.