> ## 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-CN/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-CN/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.