> 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/github-pull-request-preview.md).

# GitHub 拉取请求预览

在 GitHub 中创建拉取请求时查看你的内容预览

当你向已同步到 GitBook 分区的 GitHub 分支提交拉取请求（PR）时，可以在合并前预览内容。这样，你就能在合并前检查更改带来的影响。

你可以将此功能用作合并 PR 前的最后一道检查，在将更改合并到已同步的分支之前，先在非生产环境中查看这些更改。

### 如何访问预览链接

只要你已向 [GitBook GitHub 应用](https://github.com/apps/gitbook-com) 授予 PR 所需的只读权限，此功能就会开箱即用。

每当你使用与 GitBook 分区同步的目标分支创建 PR 时，PR 中都会显示一条状态，其中包含唯一的预览 URL。点击该状态上的 **详情** 链接即可打开内容的预览 URL。随后，你可以在合并 PR 前确认内容是否符合预期。

{% hint style="info" %}
只有拥有 GitBook 账户的用户才能访问预览链接。
{% endhint %}

### 安全注意事项

出于安全原因，GitBook 目前默认不会为从仓库分叉创建的 PR 生成预览。由于 PR 预览内容会通过你自己的域名提供服务，无论域名是 `.gitbook.io` 还是你的自定义域名，用户都可能在你公开仓库的分叉中生成恶意内容，并以你的名义发布这些内容。

你可以在 Git Sync 设置中通过一个选项显式配置此功能。

### 常见问题

#### 为什么我无法在拉取请求中预览 GitBook 文档？

常见原因：

* **你的网站尚未发布。** PR 预览 URL 由你已发布的文档网站提供（域名为 `.gitbook.io` 或你的自定义域名）。
* **你的网站启用了身份验证访问限制。** 对于通过 [身份验证访问限制](https://gitbook.com/docs/documentation/zh/publish/site-audience/authenticated-access.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/github-pull-request-preview.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.
