> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/zh/getting-started/git-sync/enabling-github-sync.md).

# 启用 GitHub 同步

### 入门

在你想与 GitHub 仓库同步的章节中，点击 **设置** 旁边的 **Git 同步** 在 [章节标题](/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" %}
如果你在此步骤看到 **“可能存在重复账户”** 错误消息，这意味着你的 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：** 所选的 GitHub 分支是权威来源。仅当你的章节可以接收该分支的内容时，才使用此方向。

{% hint style="warning" %}
**GitHub → GitBook 可能会替换你章节的内容。** 如果你选择了一个空仓库，GitBook 可能会用该仓库的空内容替换你的章节。

在开始初始同步之前，请确认仓库、分支和方向。确保目标内容可以安全替换。
{% endhint %}

准备就绪后，开始初始同步。

### 如果你选择了错误的方向

Git 同步操作会显示在该章节的 **版本历史**中。找到紧挨着 Git 同步操作之前的修订版本，然后点击 **回滚** 以恢复之前的章节内容。

有关详细步骤，请参阅 [版本控制](/docs/documentation/zh/creating-content/version-control.md#roll-back-to-a-previous-version).

断开 Git 同步会停止未来的同步。它不会自动恢复内容。

如果同步前的修订版本不可用，或者你无法完成回滚， [请联系 GitBook 支持](https://gitbook.com/docs/help-center/further-help/how-do-i-contact-support).

### 编写并提交

你可以开始了。你会注意到，如果你的章节处于 [实时编辑](/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
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://gitbook.com/docs/documentation/zh/getting-started/git-sync/enabling-github-sync.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.
