# 启用 GitHub 同步

### 入门指南

在你想与 GitHub 仓库同步的空间中，前往 [空间页眉](/docs/documentation/zh/zi-yuan/gitbook-ui.md#space-header) 右上角的 **配置**并选择 **GitHub 同步**.

<figure><img src="/files/bcdd5cd4b8402f35d1d6c60961a63d2c0d21c142" alt="A GitBook screenshot showing GitHub Sync configuration options"><figcaption><p>GitHub 同步配置选项。</p></figcaption></figure>

### 通过 GitHub 进行身份验证

如果你是第一次设置 GitHub 同步，并且尚未关联 GitHub 账户，那么在你开始配置 Git 同步时，系统会提示你进行关联。如果你已经关联了账户，仍然可能需要通过 GitHub 进行身份验证。

{% hint style="warning" %}
如果你看到 **“Potential duplicated accounts”** 错误信息，这意味着你的 GitHub 账户已经与另一个 GitBook 用户账户关联。

为了帮助你识别哪些账户已关联，你需要先退出当前会话，并使用 GitHub 登录方式重新登录。

如果你已经知道与你的 GitHub 关联的 GitBook 账户，你可以先登录到该用户账户，并解除 GitHub 账户的关联（在设置中完成），然后再重新登录并关联你当前的账户。

在我们的 [故障排除页面](/docs/documentation/zh/getting-started/git-sync/troubleshooting.md#potential-duplicated-accounts-when-signing-in).
{% endhint %}

### 将 GitBook 应用安装到你的 GitHub 账户

如果你还没有这样做，你会看到一个提示，要求将 [GitBook 应用](https://github.com/apps/gitbook-com) 添加到你的 GitHub 账户。

按照 GitHub 弹出框中的说明操作，根据你的需要，向 GitBook 授予特定仓库的权限，或允许访问所有仓库。

### 选择一个仓库和分支

选择你希望与 GitBook 内容保持同步的账户和仓库。

{% hint style="info" %}
**找不到你的仓库？** 如果你在列表中找不到你的仓库，请确保你已在 [GitBook GitHub 应用](https://github.com/apps/gitbook-com) 中以正确的范围（即你的个人账户或该仓库所在的 GitHub 组织）进行了安装。你还应检查是否已在 GitBook GitHub 应用中配置了正确的仓库访问权限。
{% endhint %}

选择正确的仓库后，选择你希望提交推送到并同步自哪个分支。

### 执行初始同步

首次同步时，你可以选择两个方向之一进行同步：

1. GitBook -> GitHub 将把你空间中的内容同步到 **所选分支。** 如果你是从一个空仓库开始，并希望快速将 GitBook 内容导入，这会非常适合。
2. GitHub -> GitBook 将把你空间中的内容同步 **自** 所选分支。如果你在仓库中已有 Markdown 内容，并希望将其导入 GitBook，这会非常适合。

### 编写并提交

你已经可以开始了。你会注意到，如果你的空间处于 [实时编辑](/docs/documentation/zh/collaboration/live-edits.md) 模式，实时编辑现在已被锁定。这样一来，当你团队中的某个人合并了一个[ 更改请求](/docs/documentation/zh/collaboration/change-requests.md) 到 GitBook 时，我们就能可靠地将内容同步到你的仓库。

当你在 GitBook 中编辑时，每次更改请求合并都会生成一条提交到你所选的 GitHub 分支。

当你向 GitHub 提交时，每次提交都会作为历史提交同步到你的 GitBook 空间。

{% hint style="warning" %}
目前，为我们的 GitHub 集成提供支持的 GitHub 应用暂不对 GitHub Enterprise Server 实例上的客户开放。
{% endhint %}


---

# Agent Instructions: 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:

```
GET https://gitbook.com/docs/documentation/zh/getting-started/git-sync/enabling-github-sync.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
