> For the complete documentation index, see [llms.txt](https://overleaf-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://overleaf-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/" 
        # 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 用戶端時，使用者需要 Personal Access Token。使用者可以透過應用程式 UI 管理 Personal Access Token（請參閱文件）：

<figure><img src="/files/aa7b2d41aa524a14af68c01cb4ccf1bd6de9f36d" alt=""><figcaption><p>Git 整合 Personal Access Token</p></figcaption></figure>
{% endstep %}

{% step %}

### 監控與資源考量

我們建議您在啟用後監控主機資源 `git-bridge`。負載增加將取決於：

* 使用該功能的使用者數量
* 您的執行個體中託管的專案類型（較大的專案通常更耗費資源）
  {% endstep %}
  {% endstepper %}

### 將專案交換到 S3

Git 整合會在磁碟上為每個被使用者複製的專案儲存完整的 git repository。如果您的磁碟空間有限，可以啟用交換工作，將較少使用的 repository 移至 AWS S3。若之後再次需要已交換的 repository，會再移回磁碟。以下環境變數會控制交換工作：

| 名稱                                    | 描述                                                                              |
| ------------------------------------- | ------------------------------------------------------------------------------- |
| `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 repositories                                                   |
| `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://overleaf-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.
