> 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/docs-as-code/git-sync.md).

# GitHub 与 GitLab 同步

使用 GitBook 的双向集成，将你的 GitBook 文档与 GitHub 或 GitLab 同步

<figure><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-9aece8d02ab2c3f0ae5b824fc4cdb37b2100ccbf%2FSite-wide%20Git%20Sync.png?alt=media" alt="A GitBook screenshot showing the Git Sync setup"><figcaption><p>为你的 GitBook 文档设置 Git Sync。</p></figcaption></figure>

### 概览

Git Sync 允许技术团队将 GitHub 或 GitLab 仓库与 GitBook 同步，并将一个由 Markdown 文件组成的仓库转换为美观、易用的文档。在 GitBook 强大的编辑器中直接编辑，同时保持内容与 GitHub 或 GitLab 上的代码库同步。

Git Sync 是双向同步的，因此你在 GitBook 编辑器中直接所做的更改会自动同步，GitHub 或 GitLab 上的任何提交也是如此。这使开发者可以直接从 GitHub 或 GitLab 提交，而技术写作者、教学设计师和产品经理则可以在 GitBook 中直接编辑、讨论并对更改提供反馈。

如需通过代码配置仓库目录、内容根目录、首页或导航，请参阅 [内容配置](https://gitbook.com/docs/documentation/zh/docs-as-code/git-sync/content-configuration.md) ，了解 `gitbook-docs.yaml`, `.gitbook.yaml`和 `SUMMARY.md`.

### 设置 Git 同步

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><h4><i class="fa-github">:github:</i></h4></td><td><h4>设置 GitHub 同步</h4></td><td>为 GitBook 设置并授权 GitHub 集成。</td><td><a href="https://gitbook.com/docs/documentation/zh/docs-as-code/git-sync/enabling-github-sync.md">启用 GitHub 同步</a></td></tr><tr><td><h4><i class="fa-gitlab">:gitlab:</i></h4></td><td><h4>设置 GitLab 同步</h4></td><td>为 GitBook 设置并授权 GitLab 集成。</td><td><a href="https://gitbook.com/docs/documentation/zh/docs-as-code/git-sync/enabling-gitlab-sync.md">启用 GitLab 同步</a></td></tr></tbody></table>

{% hint style="info" %}
Git Sync 支持企业客户的 IP 白名单。如果你的 GitHub、GitLab 或内部网络只接受来自已批准 IP 的流量，请在启用集成之前将这些 Git Sync 出站 IP 加入白名单：

* `34.136.22.210`
* `34.29.189.57`
* `35.223.181.150`
* `34.72.115.112`
* `136.116.236.109`
  {% endhint %}

{% hint style="info" %}
只有 [管理员和创建者](https://gitbook.com/docs/documentation/zh/collaborate/member-management/roles.md) 才能启用和配置 Git Sync。
{% endhint %}

### 与 AI 代理协作

在使用 Git Sync 于本地处理文档时，您可以使用 GitBook 的 [skill.md 文件](https://gitbook.com/docs/documentation/zh/docs-as-code/ai-coding-assistants-and-skillmd.md) 为 AI 编程助手提供有关 GitBook 区块、功能和最佳实践的上下文信息。

前往 [Agent skills](https://gitbook.com/docs/documentation/zh/docs-as-code/ai-coding-assistants-and-skillmd.md) 了解更多。


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://gitbook.com/docs/documentation/zh/docs-as-code/git-sync.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
