Protocol overview
The Git Smart HTTP Protocol uses a stateless request-response model with two main endpoints:- git-upload-pack: Handles fetch and pull operations (read access)
- git-receive-pack: Handles push operations (write access)
Protocol version
Gitflare uses:- Protocol v2 for git-upload-pack (fetch/pull operations)
- Protocol v1 for git-receive-pack (push operations)
The git-receive-pack endpoint currently uses protocol v1 but is planned to be upgraded to v2 in future releases.
Authentication
All Git protocol endpoints support HTTP Basic Authentication:- Read operations (upload-pack): Allow anonymous access for public repositories
- Write operations (receive-pack): Always require authentication
401 Unauthorized response with a WWW-Authenticate header.
Capability discovery
Clients discover server capabilities by making a GET request to the info/refs endpoint:Upload-pack capabilities (protocol v2)
The server advertises these capabilities for fetch operations:version 2: Protocol versionagent=gitflare/0.0.1: Server identificationls-refs: List references command supportfetch: Fetch objects command supportside-band-64k: Multiplexed progress messagesobject-format=sha1: SHA-1 object format
Receive-pack capabilities (protocol v1)
The server advertises these capabilities for push operations:report-status: Send detailed status reportdelete-refs: Support for deleting referencesatomic: All-or-nothing push transactionsno-thin: Do not use thin pack formatagent=gitflare/0.0.1: Server identificationsymref=HEAD:refs/heads/{branch}: Symbolic HEAD reference
Pkt-line format
All protocol messages use the pkt-line format defined in the Git wire protocol:0000: Flush packet (end of message)0001: Delimiter packet (section separator)0002: Response-end packet (end of response)
apps/web/src/git/pkt.ts:46 for the implementation.
Request flow
Fetch operation (pull/clone)
-
Client requests capability advertisement:
-
Client sends ls-refs command to list available references:
-
Client sends fetch command with wants and haves:
- Server responds with packfile containing requested objects
Push operation
-
Client requests capability advertisement:
-
Client sends reference updates and packfile:
- Server responds with status report for each reference update
Implementation details
The protocol implementation is distributed across several files:apps/web/src/git/protocol.ts: Core protocol functionsapps/web/src/git/pkt.ts: Pkt-line encoding/decodingapps/web/src/git/service.ts: Git operations using isomorphic-gitapps/web/src/do/repo.ts: Durable Object handling requestsapps/web/src/routes/$owner/$repo/: HTTP route handlers
Error handling
Errors are communicated using:- HTTP status codes (401, 404, 500)
- Pkt-line error packets starting with
ERR - Side-band channel 3 for packfile errors
Related endpoints
git-upload-pack
Fetch and pull operations endpoint
git-receive-pack
Push operations endpoint