> 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-tw/she-ding/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/" 
        # "http://sharelatex/api/v0/" 適用於 4.1.6 版及更早版本
        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 用戶端時，使用者需要個人存取權杖。使用者可透過應用程式 UI 管理個人存取權杖（請參閱文件）：

<figure><img src="/files/aa7b2d41aa524a14af68c01cb4ccf1bd6de9f36d" 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-tw/she-ding/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.
