> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/on-premises/zh-cn/pei-zhi/overleaf-toolkit/git-integration.md).

# Git 集成

Git 集成功能仅在 [ayaka-notes/overleaf](https://github.com/ayaka-notes/overleaf) 当前可用。

{% hint style="info" %}
此功能最初由 [ayaka-notes/overleaf-pro](https://github.com/ayaka-notes/overleaf-pro).
{% endhint %}

{% stepper %}
{% step %}

### 启用 git-bridge（仅适用于 Toolkit 用户）

如果你正在使用 Toolkit，请通过在你的 `git-bridge` 中设置以下内容来启用 `config/overleaf.rc`:

{% code title="config/overleaf.rc" %}

```
GIT_BRIDGE_ENABLED=true
```

{% endcode %}
{% endstep %}

{% step %}

### 添加 git-bridge 容器（仅适用于 Docker Compose 用户）

对于运行自定义 `docker-compose.yml`，请将以下容器配置添加到你的 compose 文件中：

{% code title="docker-compose.yml（git-bridge 服务）" overflow="wrap" %}

```yaml
git-bridge：
    restart: always
    image: quay.io/sharelatex/git-bridge:4.0.0 # 标签应与 `sharelatex` 容器标签匹配
    volumes:
        - ~/git_bridge_data:/data/git-bridge
    container_name: git-bridge
    expose:
        - "8000"
    environment:
        GIT_BRIDGE_API_BASE_URL: "http://sharelatex:3000/api/v0/" 
        # 适用于 4.1.6 及更早版本的 "http://sharelatex/api/v0/"
        GIT_BRIDGE_OAUTH2_SERVER: "http://sharelatex"
        GIT_BRIDGE_POSTBACK_BASE_URL: "http://git-bridge:8000"
        GIT_BRIDGE_ROOT_DIR: "/data/git-bridge"
    user: root
    command: ["/server-pro-start.sh"]
```

{% endcode %}
{% endstep %}

{% step %}

### 更新 sharelatex 容器配置

你还需要将 `git-bridge` 容器链接到 `sharelatex` 容器中，并定义以下环境变量，请注意 `V1_HISTORY_URL`:

<pre class="language-yaml" data-title="docker-compose.yml（sharelatex 服务）"><code class="lang-yaml">sharelatex:
    links：
        - git-bridge
    environment:
         GIT_BRIDGE_ENABLED: true
         GIT_BRIDGE_HOST: "git-bridge"
         GIT_BRIDGE_PORT: "8000"
<strong>         # 我们现在使用 v1，如果你以前设置过 V1_HISTORY_URL，请现在更新
</strong><strong>         V1_HISTORY_URL: "http://sharelatex:3054"
</strong></code></pre>

{% endstep %}

{% step %}

### 身份验证

在对 git 客户端进行身份验证时，用户需要个人访问令牌。用户可以通过应用程序界面管理个人访问令牌（请参阅文档）：

<figure><img src="/files/a1105f7b5201b73f209dfbd60c36c96bd18950b0" alt=""><figcaption><p>Git 集成个人访问令牌</p></figcaption></figure>
{% endstep %}

{% step %}

### 监控与资源注意事项

我们建议你在启用后监控主机资源 `git-bridge`。负载增加将取决于：

* 访问该功能的用户数量
* 你实例中托管的项目类型（较大的项目通常更消耗资源）
  {% endstep %}
  {% endstepper %}

### 将项目交换到 S3

Git 集成会为每个被用户克隆的项目在磁盘上存储一个完整的 git 仓库。如果你的磁盘空间有限，你可以启用一个交换任务，将使用较少的仓库移动到 AWS S3。如果之后再次需要某个已交换出去的仓库，它会被移回磁盘。以下环境变量控制交换任务：

| 名称                                    | 描述                                                                             |
| ------------------------------------- | ------------------------------------------------------------------------------ |
| `GIT_BRIDGE_SWAPSTORE_TYPE`           | 将其设置为 "s3" 以启用交换任务。                                                            |
| `GIT_BRIDGE_SWAPSTORE_AWS_ACCESS_KEY` | 你的 AWS 访问密钥                                                                    |
| `GIT_BRIDGE_SWAPSTORE_AWS_SECRET`     | 你的 AWS 密钥                                                                      |
| `GIT_BRIDGE_SWAPSTORE_S3_BUCKET_NAME` | 该存储桶将包含压缩后的 git 仓库                                                             |
| `GIT_BRIDGE_SWAPSTORE_AWS_REGION`     | 存储桶所在区域                                                                        |
| `GIT_BRIDGE_SWAPJOB_MIN_PROJECTS`     | <p>磁盘上至少保留多少个项目。<br><br><strong>- 默认值：</strong> 50</p>                         |
| `GIT_BRIDGE_SWAPJOB_LOW_GIB`          | <p>交换的低水位线。交换任务会移动项目，直到磁盘使用量低于此值。<br><br><strong>- 默认值：</strong> 128 GB</p>    |
| `GIT_BRIDGE_SWAPJOB_HIGH_GIB`         | <p>交换的高水位线。磁盘使用量达到此值时，交换任务将开始交换。<br><br><strong>- 默认值：</strong> 256 GB</p>     |
| `GIT_BRIDGE_SWAPJOB_INTERVAL_MILLIS`  | <p>检查磁盘使用量并运行交换任务之间的时间间隔。<br><br><strong>- 默认值：</strong> 3600000 毫秒 = 1 小时</p> |

### 问答

<details>

<summary>如果我与他人共享我的项目，Git Bridge 的权限模型如何工作？</summary>

只有只读权限的用户才能克隆此项目；具有读写权限的用户可以克隆和推送项目。注意：用户需要登录后才能加入此项目。

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/on-premises/zh-cn/pei-zhi/overleaf-toolkit/git-integration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
