> This page is for version v1 (default).
> For other versions, use one of these documentation indexes:
> - v1 (default): https://docs.butterix.com/llms.txt
> - v0: https://docs.butterix.com/v0/llms.txt

> For the MDX source of any page, append .mdx to the page URL.
> For a complete documentation index, see https://docs.butterix.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.butterix.com/_mcp/server.
> If something on this page is wrong or missing, POST JSON {"page": "<page URL>", "message": "<what is wrong>"} to https://docs.butterix.com/_biti/feedback/agent.

# 连接 Git 仓库

`PUT /sites/{site}/git`

需要 `admin` 角色。用远程仓库替换托管仓库，立即拉取并开始一次生产部署。
私有仓库需要提供具有读取权限的访问令牌（加密存储）；使用可视化编辑器发布时还需要写权限。
连接后请在仓库中配置 Webhook（地址与密钥见响应中的 `git`）。

Base URL: https://api.butterix.com/v1

Authentication: bearer token in Authorization header or API key in cookie `biti_session`

## Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `site` | string | yes | 站点 slug 或 id |

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `url` | string | yes | https 地址 |
| `branch` | string | no |  |
| `token` | string | no | 访问令牌；留空时保留已有令牌 |

## Example request

```bash
curl -X PUT https://api.butterix.com/v1/sites/acme-payments/git \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{
         "url": "https://github.com/acme/docs.git"
       }'
```

## Responses

### 200

站点详情

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `id` | string | no |  |
| `slug` | string | no |  |
| `name` | string | no |  |
| `url` | URL | no |  |
| `sourceType` | enum | no | 内容来源：托管仓库、外部 Git 仓库或 CLI 上传 Allowed: `hosted`, `git`, `upload`. |
| `status` | enum | no | 最近一次部署的状态，没有部署时为 `none` Allowed: `queued`, `building`, `ready`, `failed`, `canceled`, `none`. |
| `updatedAt` | integer | no |  |
| `pageCount` | integer | no | 生产部署的页面数 |
| `orgSlug` | string | no |  |
| `git` | object | no | 连接了 Git 仓库时存在 |
| `git.url` | string | no |  |
| `git.branch` | string | no |  |
| `git.hasToken` | boolean | no |  |
| `git.webhookUrl` | string | no |  |
| `git.webhookSecret` | string | no |  |
| `production` | object | no |  |
| `production.id` | string | no |  |
| `production.siteId` | string | no |  |
| `production.kind` | enum | no | Allowed: `production`, `preview`. |
| `production.status` | enum | no | Allowed: `queued`, `building`, `ready`, `failed`, `canceled`. |
| `production.source` | string | no | `cli`（上传）、`hosted`（托管仓库）或 `git` |
| `production.branch` | string | no |  |
| `production.commitSha` | string | no |  |
| `production.message` | string | no |  |
| `production.createdBy` | object | no | 触发者；用 API Key 触发时是创建密钥的人 |
| `production.createdBy.id` | string | no |  |
| `production.createdBy.name` | string | no |  |
| `production.apiKey` | object | no | 用 API Key（CLI / CI）触发时，密钥的名称与首尾 |
| `production.apiKey.name` | string | no |  |
| `production.apiKey.prefix` | string | no | 密钥前 10 个字符 |
| `production.apiKey.suffix` | string | no | 密钥末尾 10 个字符 |
| `production.error` | string | no | 失败原因 |
| `production.pageCount` | integer | no |  |
| `production.sizeBytes` | integer | no |  |
| `production.durationMs` | integer | no |  |
| `production.url` | URL | no | 成功后才有。生产部署是站点地址，预览部署是 `<site>--<id 后 8 位>` 子域名 |
| `production.isCurrent` | boolean | no | 是否为当前生产部署 |
| `production.createdAt` | integer | no |  |
| `production.finishedAt` | integer | no |  |
| `domains` | list of objects | no |  |
| `domains[].domain` | string | no |  |
| `domains[].verified` | boolean | no |  |
| `domains[].primary` | boolean | no | 是否为主域名 |
| `domains[].verifyRecord` | object | no | 需要添加的 TXT 记录 |
| `domains[].verifyRecord.type` | "TXT" | no | Allowed: `TXT`. |
| `domains[].verifyRecord.name` | string | no |  |
| `domains[].verifyRecord.value` | string | no |  |
| `domains[].cname` | string | no | CNAME 目标 |
| `domains[].createdAt` | integer | no |  |
| `access` | object | no |  |
| `access.mode` | enum | no | Allowed: `public`, `password`. |
| `ai` | object | no |  |
| `ai.enabled` | boolean | no |  |
| `ai.provider` | enum | no | Allowed: `anthropic`, `deepseek`, `openrouter`. |
| `ai.model` | string | no |  |
| `ai.hasKey` | boolean | no | 是否设置了站点密钥 |
| `ai.keyMasked` | string | no |  |
| `ai.platformKeyAvailable` | boolean | no | 平台是否为当前提供商配置了默认密钥 |
| `ai.platformKeys` | map from strings to booleans | no | 每个提供商是否有平台密钥 |
| `ai.guidance` | string | no |  |
| `ai.effort` | enum | no | 推理强度；`null` 表示使用模型的建议档位 May be null. Allowed: `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`. |
| `ai.retentionDays` | integer | no | 提问记录保留天数；`null` 表示一直保留 May be null. |
| `ai.dailyLimit` | integer | no | 滚动 24 小时内调用模型的提问上限；`null` 表示不限 May be null. |
| `ai.agent` | boolean | no | 控制台 AI 是否启用 |
| `ai.gaps` | boolean | no | 是否每天自动整理文档缺口 |
| `ai.support` | object | no | 答不上时转人工 |
| `ai.support.enabled` | boolean | no |  |
| `ai.support.url` | string | no |  |
| `ai.support.email` | string | no |  |
| `primaryUrl` | URL | no | 主域名的地址；没有自定义域名时与 `url` 相同 |
| `mcpUrl` | URL | no |  |

### 400

请求参数无效

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `error` | string | yes | 人类可读的错误信息 |
| `code` | string | no | 机器可读的错误码（部分接口提供） |

### Example response (200)

```json
{
  "id": "site_2m4k8p",
  "slug": "acme-payments",
  "name": "Acme 文档",
  "url": "https://acme-payments-sites.butterix.com",
  "sourceType": "hosted",
  "status": "queued",
  "updatedAt": 1,
  "pageCount": 94,
  "orgSlug": "acme",
  "git": {
    "url": "https://github.com/acme/docs.git",
    "branch": "main",
    "hasToken": true,
    "webhookUrl": "https://api.butterix.com/v1/webhooks/github/site_2m4k8p",
    "webhookSecret": "string"
  },
  "production": {
    "id": "dpl_01jd8x2k7q",
    "siteId": "site_2m4k8p",
    "kind": "production",
    "status": "queued",
    "source": "git",
    "branch": "main",
    "commitSha": "9fceb02d0ae598e95dc970b74767f19372d61af8",
    "message": "docs: 更新快速开始",
    "createdBy": {
      "id": "string",
      "name": "string"
    },
    "apiKey": {
      "name": "GitHub Actions",
      "prefix": "biti_a1B2c",
      "suffix": "Kd82mQx0Zt"
    },
    "error": "string",
    "pageCount": 94,
    "sizeBytes": 5832110,
    "durationMs": 6120,
    "url": "https://acme-payments--8x2k7q-sites.butterix.com",
    "isCurrent": true,
    "createdAt": 1,
    "finishedAt": 1
  },
  "domains": [
    {
      "domain": "docs.acme.com",
      "verified": false,
      "primary": false,
      "verifyRecord": {
        "type": "TXT",
        "name": "_butterix.docs.acme.com",
        "value": "butterix-verify=a1b2c3d4e5f6"
      },
      "cname": "sites.butterix.com",
      "createdAt": 1
    }
  ],
  "access": {
    "mode": "public"
  },
  "ai": {
    "enabled": true,
    "provider": "anthropic",
    "model": "claude-opus-5-5",
    "hasKey": true,
    "keyMasked": "sk-a…9f2c",
    "platformKeyAvailable": true,
    "platformKeys": {
      "key": true
    },
    "guidance": "string",
    "effort": "none",
    "retentionDays": 1,
    "dailyLimit": 200,
    "agent": true,
    "gaps": false,
    "support": {
      "enabled": false,
      "url": "",
      "email": ""
    }
  },
  "primaryUrl": "https://docs.acme.com",
  "mcpUrl": "https://docs.acme.com/_mcp/server"
}
```
