> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# GitHub 同步

> 連結您的 GitHub 帳號、匯入或匯出專案、雙向同步變更，以及解除連結。

將專案連接至 GitHub 儲存庫。變更會雙向同步，而且只會在您點選 **Sync** 時進行：不會自動同步任何內容。

> [!NOTE]
>
> 如果您在 **Account settings** 或編輯器中看不到 GitHub 選項，請要求管理員啟用 [GitHub 同步](https://ayakaleaf-pro.mintlify.site/zh-TW/on-premises/configuration/overleaf-toolkit/integrations/github-synchronisation.md)。

## 連結您的 GitHub 帳號

這只需要做一次。

**1. 開啟帳號設定**

點選 **Account**，然後點選 **Account settings**。捲動至 **GitHub**，點選 **Link**。

![帳號設定中的 GitHub 區段，含有 Link 按鈕](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-link.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=8812ab1604914a8aa6c1f0937f0e1b2e)

帳號設定中的 GitHub

**2. 在 GitHub 上授權**

GitHub 會開啟。如有要求請登入，然後授權該應用程式。

**3. 檢查連結**

您會回到帳號設定，按鈕現在顯示為 **Unlink**。

![帳號設定中的 GitHub 區段，含有 Unlink 按鈕](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-linked.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=910b756aa0adea66bda5bb2e5776214e)

您的 GitHub 帳號已連結

如果您的帳號尚未連結，**Import from GitHub** 與編輯器中的 **GitHub** 卡片會先要求您連結帳號。點選 **Link to your GitHub account**。您同樣會進入帳號設定，如果是從編輯器開始，則會在新分頁中開啟。然後返回並重新開始。

![含有 Link to your GitHub account 按鈕的 Import from GitHub 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-link-prompt.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=05546893169a57f837a8938f904db194)

帳號未連結時的提示

## 匯入儲存庫

這會從 GitHub 儲存庫建立新專案，並且已與該儲存庫連結。

**1. 開啟匯入對話方塊**

在專案頁面中，點選 **New project**，然後點選 **Import from GitHub**。

![含有 Import from GitHub 的 New project 選單](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-new-project-menu.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=384e6663f982016a5c295f35c4709413)

New project 選單

> [!NOTE]
>
> 擁有專案後才會出現 **New project**。歡迎頁面上的 **Create a new project** 選單沒有匯入功能，因此請先建立一個空白專案。

**2. 選擇儲存庫**

點選儲存庫旁的 **Import to Overleaf**。清單包含您的儲存庫以及您所屬組織的儲存庫。

![列出四個儲存庫的 Import from GitHub 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-import.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=54a0bd11655ddbfad4ae16e5e7473b74)

您的 GitHub 儲存庫

如果缺少某個組織的儲存庫，請點選 **Can't see what you're looking for?**，查看 GitHub 關於為該組織核准應用程式的說明。

**3. 檢查專案**

新專案會開啟，並包含儲存庫中的檔案。

![編輯器顯示匯入的專案及其檔案與編譯後的 PDF](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-imported.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=90dfe6947c2e0ed420abfc8c81992768)

匯入的專案

## 將專案匯出至新的儲存庫

這會從您擁有的專案建立儲存庫，並將兩者連結。專案只能透過這種方式或匯入來連結：您無法將它連結至已存在的儲存庫。

**1. 在編輯器中開啟 GitHub**

開啟專案。在左側欄中點選 **Integrations**，然後點選 **GitHub**。

![含有 GitHub 卡片的 Integrations 面板](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-integrations.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=5c96ec0031a5940c337393254b06e0d3)

Integrations 面板

**2. 填寫儲存庫資訊**

選擇 **Owner**，可以是您自己，也可以是您所屬的某個組織。**Repository Name** 預設為專案名稱。描述為選填，**Private** 預設為已選取。點選 **Create a GitHub repository**。

![已填寫的 Export Project to GitHub 表單](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-export.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=24bd26a171943d43efaa3c4aed69d1e8)

Export Project to GitHub

**3. 檢查連結**

對話方塊現在顯示 **This project is linked to** 以及儲存庫名稱。

![匯出後的 Sync with GitHub 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-exported.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=93ebf2c62d4a34c7d2c41ffbca9d0740)

專案已連結

## 同步

**1. 開啟同步對話方塊**

開啟已連結的專案。在左側欄中點選 **Integrations**，然後點選 **GitHub**。

**Recent commits in GitHub** 會列出即將進入專案的內容。

![列出一個新提交的 Sync with GitHub 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-new-commits.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=6a3c23a6993f04d0fa818bceb565ce3e)

GitHub 中有一個新提交在等待

**2. 描述您的變更**

如果您在專案中做了變更，會出現提交訊息欄位。此欄位為選填：如果留空，提交名稱為 `Updates from Overleaf`。

![已填寫提交訊息的 Sync with GitHub 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-commit-message.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=b3fe2cbcae8335c7363fcd220d2b993c)

您的變更的提交訊息

**3. 點選 Sync**

點選 **Sync**。來自 GitHub 的新提交會進入專案，您的變更會推送至儲存庫的預設分支。如果兩邊修改了不同的內容，系統會為您合併。

**4. 檢查結果**

對話方塊顯示 **No new commits in GitHub since last merge.**，提交訊息欄位也消失了。編輯器中的檔案與 GitHub 上的提交都已是最新狀態。

![同步後沒有新提交的 Sync with GitHub 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-done.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=851a620d8601a3ebaf9260f0f1c1685a)

一切皆已同步

### 如果兩邊修改了相同的行

對話方塊會提示無法合併變更，並指出一個新分支 `overleaf-YYYY-MM-DD-HHMMSS`，其中保存了您的變更。

![含有合併衝突警告的 Sync with GitHub 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-conflict.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=b67dd69bb98605672da34b3a372be582)

衝突

1. 在 GitHub 上或使用 Git 將該分支合併至預設分支。在此期間您可以關閉對話方塊：再次開啟時會顯示相同的訊息。
2. 點選 **I have manually merged. Continue**。合併後的結果會進入專案。
3. 該分支會保留在 GitHub 上。不再需要時請將其刪除。

## 解除專案連結

當您不再希望專案同步時執行此操作。只有專案擁有者可以執行。

**1. 點選 Unlink**

在同步對話方塊中，點選 **Unlink**。

**2. 確認**

點選 **Confirm**。關於訂閱的提示不會妨礙您再次連結該專案。

![要求確認解除連結的 Sync with GitHub 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-unlink-project.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=e2f2e541c2e9e8d000baa0dacd28a328)

確認解除連結

**3. 檢查結果**

對話方塊現在顯示 **Export Project to GitHub**。專案與儲存庫都會保留各自的內容。若要再次同步，請將專案匯出至新的儲存庫，或將儲存庫匯入為新專案。

## 解除您的 GitHub 帳號連結

在 **Account settings** 的 **GitHub** 下，點選 **Unlink**，然後在對話方塊中再次點選 **Unlink**。

![Unlink GitHub Account 對話方塊](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/github-sync-unlink-account.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=94ce090cb4d8b98231886319d6e6d903)

解除您的帳號連結

您的專案仍與各自的儲存庫保持連結。在您再次連結帳號之前，無法同步它們。

> [!NOTE]
>
> 關於共用專案中誰可以做什麼，請參閱[誰可以連結與同步](https://ayakaleaf-pro.mintlify.site/zh-TW/on-premises/configuration/overleaf-toolkit/integrations/github-synchronisation.md#who-can-link-and-sync)。每位進行同步的協作者都需要連結自己的 GitHub 帳號。


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