> ## Documentation Index
> Fetch the complete documentation index at: https://docs.archil.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Git hosting

> Create git repos from code. Each repo is an Archil disk in your own account, cloned and pushed over HTTPS with scoped, expiring tokens.

Archil Git hosting gives you git repos that you create and manage from code. Each repo is an Archil disk in your own
account, served by a small git service that also runs in your account. Your agents and users clone, fetch, and push
over HTTPS with ordinary `git`, using tokens you mint per repo.

* **Git over HTTPS:** standard `git clone`, `fetch`, and `push`, with scoped, expiring tokens. `git` never sees your API key.
* **Git LFS:** works with no setup. LFS objects are stored on the repo's disk.
* **Commit without git:** make a commit from a list of file changes with one API call, without a clone. See
  [Commit without git](https://docs.archil.com/git/commits.md).
* **Instant forks:** a fork is a copy-on-write copy of the repo's disk, ready in about a second whatever the repo's size.
  See [Forks](https://docs.archil.com/git/forks.md).
* **Push webhooks:** one signed webhook per account for every push and commit. See [Push webhooks](https://docs.archil.com/git/webhooks.md).
* **Read without cloning:** list refs, browse trees, read files, page through history, and compare branches over HTTPS.
* **In your account:** repos, the git service, and its state are disks and sandboxes in your account. The service keeps
  itself up to date and pauses when idle.

```typescript theme={null}
import { Archil } from "disk";

const archil = new Archil({ git: { endpoint: process.env.ARCHIL_GIT_URL } });
const repo = await archil.git.repos.create({ name: "my-app" });
const { env } = await archil.git.tokens.credentials(repo, { scope: "write", ttlSeconds: 600 });
// git clone, commit and push with `env` in the environment
```

> [!NOTE]
>
> Git hosting is in preview, and the API may change before 1.0. Enable it from **Git hosting** in the
> [Archil console](https://console.archil.com). Questions and feedback go to
> [support@archil.com](mailto:support@archil.com).

## Quickstart

### 1. Enable Git hosting

1. In the [Archil console](https://console.archil.com), open **Git hosting** in the workspace that should hold your
   repos, and enable it. The console sets up the git service in your account.
2. Copy the **endpoint** that page shows. This is your git endpoint: the SDK sends every Git hosting call there, and
   your repos' remote URLs are on it.
3. Use an [API key](https://console.archil.com/api-keys) from the same workspace.

### 2. Configure the SDK

Install the SDK and pass the endpoint to the `Archil` client. If you don't pass it, the SDK reads `ARCHIL_GIT_URL`.

```bash TypeScript theme={null}
npm install disk
```

```bash Python theme={null}
pip install archil
```

```typescript TypeScript theme={null}
import { Archil } from "disk";

const archil = new Archil({
  apiKey: process.env.ARCHIL_API_KEY,
  region: "aws-us-west-2",
  git: { endpoint: process.env.ARCHIL_GIT_URL }, // the endpoint from the console
});
```

```python Python theme={null}
import os
from archil import Archil

archil = Archil(
    api_key=os.environ["ARCHIL_API_KEY"],
    region="aws-us-west-2",
    git_endpoint=os.environ["ARCHIL_GIT_URL"],  # the endpoint from the console
)
```

Without an endpoint, every `archil.git` call fails with an `ArchilGitError` whose code is `not_configured`, before
any request is sent.

### 3. Create a repo

```typescript TypeScript theme={null}
const repo = await archil.git.repos.create({ name: "my-app" });
repo.remoteUrl; // https://<your git endpoint>/<account>/my-app.git
repo.diskId;    // the Archil disk that holds it
```

```python Python theme={null}
repo = archil.git.repos.create(name="my-app")
repo.remote_url  # https://<your git endpoint>/<account>/my-app.git
repo.disk_id     # the Archil disk that holds it
```

The default branch is `main`. Pass `defaultBranch` (`default_branch` in Python) to change it.

### 4. Mint a token and push

`git` and Git LFS accept only tokens that you mint for specific repos, never your API key. A `read` token can clone
and fetch. A `write` token can push too.

`tokens.credentials()` mints a token for one repo and returns `env`: environment variables that make `git` send the
token to your git endpoint. Passing the token this way keeps it out of `.git/config` and off the command line.

```typescript TypeScript theme={null}
import { execFileSync } from "node:child_process";

const { env } = await archil.git.tokens.credentials(repo, { scope: "write", ttlSeconds: 600 });
const gitEnv = { ...process.env, ...env };

execFileSync("git", ["clone", repo.remoteUrl, "my-app"], { env: gitEnv });
// add files and commit in my-app, then:
execFileSync("git", ["push", "origin", "main"], { cwd: "my-app", env: gitEnv });
```

```python Python theme={null}
import os
import subprocess

creds = archil.git.tokens.credentials(repo, scope="write", ttl_seconds=600)
git_env = {**os.environ, **creds.env}

subprocess.run(["git", "clone", repo.remote_url, "my-app"], env=git_env, check=True)
# add files and commit in my-app, then:
subprocess.run(["git", "push", "origin", "main"], cwd="my-app", env=git_env, check=True)
```

To hand a token to someone or something else, mint it directly. A token can cover several repos:

```typescript TypeScript theme={null}
const { token, expiresAt } = await archil.git.tokens.mint({
  repos: [repo],
  scope: "read",
  ttlSeconds: 3600,
});
```

```python Python theme={null}
minted = archil.git.tokens.mint(repos=[repo], scope="read", ttl_seconds=3600)
minted.token, minted.expires_at
```

For other ways to give `git` a token, such as a credential helper, see [Tokens](https://docs.archil.com/git/sdk.md#tokens).

### 5. Read a file without cloning

```typescript TypeScript theme={null}
const readme = await repo.blob("main", "README.md"); // Uint8Array
const { entries } = await repo.tree("main", "src");
const { commits } = await repo.log({ ref: "main", limit: 20 });
```

```python Python theme={null}
readme = repo.blob("main", "README.md")  # bytes
tree = repo.tree("main", "src")
log = repo.log(ref="main", limit=20)
```

See the [read API](https://docs.archil.com/git/sdk.md#read-api) for refs, streaming large files, and comparing branches.

## How it works

Enabling Git hosting creates a few resources in your account, all in the workspace and region you enabled it in:

* **The git service,** which runs as Archil sandboxes. One of them serves your git endpoint. Repos are spread over
  shards, 4 by default, and each shard is a sandbox that starts when the first repo is placed on it. To change the
  number of shards, see [Shards](https://docs.archil.com/git/sdk.md#shards).
* **A disk per repo.** The repo's git objects, refs, and LFS objects live on it. `repo.diskId` names it.
* **A small state disk** that holds the service's own records, such as your repos and webhook settings.

The service's sandboxes pause after a few minutes without requests and resume on the next one, so a quiet account
doesn't keep them running. The service also keeps itself up to date. Manage repos through the SDK rather than by
changing these disks and sandboxes directly: deleting one of them yourself can break the service or lose repos.

## Limits

| | |
| - | - |
| Repo names | 1 to 100 characters: letters, digits, `.`, `_`, and `-`. Unique in the account |
| Token lifetime | 1 second to 24 hours (`ttlSeconds` up to 86,400) |
| Token scopes | `read` (clone, fetch, LFS download) or `write` (also push and LFS upload) |
| Commit API | 10,000 files and 64 MiB per request. See [Commit without git](https://docs.archil.com/git/commits.md#limits) |
| Webhooks | One endpoint per account, `https` only |
| Shards | 1 to 64 |
| First request after idle | Slower than a warm request. See [Performance](https://docs.archil.com/reference/benchmarks/git-hosting.md#first-operation-after-idle) |

## Performance

From an agent sandbox in AWS us-west-2, a warm push of a small commit took 119 ms at p50, a fetch 110 ms, and an
`ls-remote` 65 ms. code.storage is faster per small operation today. At 50 concurrent clients, Archil came within 6% of
code.storage's push rate, and it was the fastest of the services we measured on full and blobless clones of git.git and
on 100 MB LFS downloads. The first operation on a repo that has been idle for hours takes about half a second longer.
See [Git hosting performance](https://docs.archil.com/reference/benchmarks/git-hosting.md) for every number, the method, and where Archil is
slower.

## Next steps

> [card] [SDK reference](https://docs.archil.com/git/sdk.md)
>
> Repos, tokens, the read API, shards, and errors, in TypeScript and Python.

> [card] [Give an agent sandbox a repo](https://docs.archil.com/git/agent-sandboxes.md)
>
> Clone into a sandbox with a short-lived token and push the agent's work back.

> [card] [Commit without git](https://docs.archil.com/git/commits.md)
>
> Write files to a branch with one API call.

> [card] [Forks](https://docs.archil.com/git/forks.md)
>
> Copy a repo of any size in about a second.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.