Blob: docs/api-endpoints.md
API Endpoints Reference
Git Smart HTTP v2 Endpoints
Clone/Fetch Operations
# Clone a repository
git clone https://your-domain.com/owner/repo
# Pull updates
git pull https://your-domain.com/owner/repoGET /:owner/:repo/info/refs?service=git-upload-pack
Capability advertisement for fetch operations. Returns refs and capabilities.Advertised capabilities (protocol v2):
version 2agent=git-on-cloudflare/0.1ls-refsfetchside-band-64kofs-deltaobject-format=sha1
Note:
thin-packis not advertised.ls-refs arguments supported:
ref-prefix <prefix>โ filter refs by one or more prefixespeelโ includepeeled:<oid>attribute for annotated tagssymrefsโ includesymref-target:<ref>attribute on theHEADline
The
HEADline is emitted first when available and includessymref-targetfor compatibility. WhenHEADis unborn, the lineunborn HEADis advertised.POST /:owner/:repo/git-upload-pack
Fetch objects (clone/pull). Handles pack negotiation and object transfer.Notes:
- Streaming with side-band-64k progress.
- During negotiation (
done=false), the server returns an acknowledgments section only (nopackfilesection). - If the repository has no packs yet, the server returns
503 Service Unavailablewith headersRetry-After: 5andX-Git-Error: repository-not-ready.
Push Operations
# Push with a personal access token that has push access
git push https://owner:goc_abcd1234_secret@your-domain.com/owner/repo mainGET /:owner/:repo/info/refs?service=git-receive-pack
Capability advertisement for push operations.POST /:owner/:repo/git-receive-pack
Push objects. The Worker writes.packand.idxto R2 and commits metadata atomically via DO RPCs. One active receive lease at a time; concurrent pushes receive503 Retry-After: 10. Requires HTTP Basic credentials where the username matches:ownerand the password is a PAT withlevel: "push".
Web UI Routes
GET /
Home pageGET /:owner
List repositories for an ownerGET /:owner/:repo
Repository overview with branches, tags, and READMEGET /:owner/:repo/tree
Browse repository files
Query params:?ref=branch&path=src/libGET /:owner/:repo/blob
View file contents with syntax highlighting
Query params:?ref=branch&path=README.mdGET /:owner/:repo/commits
Commit history with pagination
Query params:?ref=branch&per_page=50&page=0GET /:owner/:repo/commits/fragments/:oid
Fetch side branch commits for a merge (AJAX endpoint)
Query params:?limit=20
Returns: HTML fragment of commit rows for dynamic insertionGET /:owner/:repo/commit/:oid
View single commit detailsGET /:owner/:repo/raw
Raw file by OID (inline by default)
Query params:?oid=...&name=file.txt[&download=1]
Notes:- Defaults to
Content-Disposition: inlineandContent-Type: text/plain; charset=utf-8for safety - Add
download=1to forceattachmentand trigger a file download
- Defaults to
GET /:owner/:repo/rawpath
Raw file by path (primarily for Markdown images and assets)
Query params:?ref=branch&path=src/file.ts&name=file.ts[&download=1]
Notes:- Best-effort
Content-Typeis derived from the file extension for inline rendering - Requires a same-origin
Refererheader (hotlink protection). Requests from other origins will be rejected with 403.
- Best-effort
Web UI JSON
GET /:owner/:repo/api/refs
Returns branch/tag refs for UI dropdowns (JSON).
Caching:Cache-Control: public, max-age=60.
Authentication And Account Management
Web UI
GET /auth
Tessera sign-in/account entry surfaceGET /auth/account
Signed-in account page for namespaces, repositories, and personal access tokens
API Endpoints
GET /auth/api/tokens
List PAT metadata for the signed-in user.POST /auth/api/tokens
Create a PAT and return the plaintext token once.DELETE /auth/api/tokens/:patId
Revoke a PAT owned by the signed-in user.POST /auth/api/repositories
Create a repository in a namespace where the signed-in user is a member.PATCH /auth/api/repositories/:repositoryId
Update repository visibility.
Admin Endpoints
Admin endpoints require a tessera-backed browser session and namespace membership.
Admin UI
GET /:owner/:repo/admin
Admin dashboard (HTML) showing refs/HEAD, compaction status, and pack stats.
Repository Management
GET /:owner/:repo/admin/refs
List all refs (JSON format)PUT /:owner/:repo/admin/refs
Update refs
Body:[{ "name": "refs/heads/main", "oid": "..." }]GET /:owner/:repo/admin/head
Get HEAD referencePUT /:owner/:repo/admin/head
Update HEAD
Body:{ "target": "refs/heads/main" }
Debug Endpoints
GET /:owner/:repo/admin/debug-state
Dump Durable Object state (JSON)GET /:owner/:repo/admin/debug-commit/:commit
Check if a commit's tree is present
Params::commitis a 40-hex SHAGET /:owner/:repo/admin/debug-oid/:oid
Check if a specific OID exists across loose, R2 loose, and packs
Params::oidis a 40-hex SHA
Compaction
POST /:owner/:repo/admin/compact
Previews compaction (dryRun=true, the default) or enqueues compaction work (dryRun=false).DELETE /:owner/:repo/admin/compact
Clears recorded compaction request.
Pack Management
DELETE /:owner/:repo/admin/pack/:packKey
Remove a specific pack and its index/metadata.
Returns:{ ok: boolean, removed: boolean, deletedPack: boolean, deletedIndex: boolean, deletedMetadata: boolean }.
Dangerous Operations
DELETE /:owner/:repo/admin/purge
Purge all repository data (R2 objects and DO state).
Body:{ "confirm": "purge-<owner>/<repo>" }
Returns: JSON result.
Warning: Destructive. Requires explicit confirmation.
Response Formats
Git Protocol
- Binary pack format for
git-upload-packandgit-receive-pack - pkt-line format for protocol messages
JSON API
All JSON endpoints return:
{
"field": "value"
// Standard JSON responses
}Error Responses
401 Unauthorized - Missing or invalid authentication
429 Too Many Requests - Rate limited (Retry-After header)
404 Not Found - Repository or resource not found
400 Bad Request - Invalid request parameters
500 Internal Server Error - Server-side error