> 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/wen-dang-ji-dai-ma/git-sync/monorepos.md).

# 单体仓库

使用站点范围的 Git Sync，从一个仓库和分支同步多个空间。将每个空间映射到其在以下位置的专属目录： `docs.yaml`.

### 站点范围的 Git Sync 如何工作

站点的 **项目目录** 设置 Git Sync 安装目录。 `docs.yaml` 位于其中。如果留空，GitBook 将使用仓库根目录。

在 `docs.yaml`中，每个空间都有一个 `content.directory`。该目录包含空间的 `.gitbook.yaml`, `README.md`, `SUMMARY.md`以及内容文件。

有关这些文件的概述，请参阅 [内容配置](/docs/documentation/zh/wen-dang-ji-dai-ma/git-sync/content-configuration.md).

### 将空间映射到目录

使用 **内容映射** 在 Git Sync 面板中映射每个空间。GitBook 会将映射保存到 `docs.yaml`.

目录路径的工作方式如下：

| 路径       | 含义               |
| -------- | ---------------- |
| `./docs` | 站点项目目录中的一个目录。    |
| `/docs`  | 仓库根目录中的一个目录。     |
| `docs`   | 与以下相同： `./docs`. |

例如，此仓库映射了三个空间：

```
/
  docs.yaml
  documentation/
    .gitbook.yaml
    README.md
    SUMMARY.md
    .gitbook/
      assets/
        logo.png
  developers/
    .gitbook.yaml
    README.md
    SUMMARY.md
  changelog/
    .gitbook.yaml
    README.md
    SUMMARY.md
```

此 `docs.yaml` 将每个空间映射到其目录：

{% code title="docs.yaml" %}

```yaml
$schema: https://api.gitbook.com/openapi.yaml#/components/schemas/GitSyncSiteConfig
site:
  structure:
    - type: space
      key: documentation
      title: 文档
      path: documentation
      content:
        directory: ./documentation
    - type: space
      key: developers
      title: 开发者
      path: developers
      content:
        directory: ./developers
    - type: space
      key: changelog
      title: 更新日志
      path: changelog
      content:
        directory: ./changelog
```

{% endcode %}

### 保持空间内容自包含

每个空间仅同步分配给它的目录。GitBook 不会自动在已映射的目录之间共享内容或资源。

将每个被引用的资源保留在其空间的映射目录中。如果多个空间需要某项资源，请在每个目录中添加一份副本，或重新组织仓库。

该 `.gitbook.yaml` `根目录` 设置控制 GitBook 在该空间映射目录内读取内容的位置。它不会使同级目录可用。

### 移动已映射的目录

通过同时更新空间的文件和映射来安全地移动空间：

1. 在仓库中，移动空间的内容文件和资源。
2. 在 `docs.yaml`，更新该空间的 `content.directory`.
3. 在同一次提交中提交这两项更改。

{% hint style="info" %}
如果 GitBook 在两项更改都存在之前导入，映射的空间可能会显示为空。
{% endhint %}

### 使用单个空间的 Git Sync

当某个空间需要使用其他仓库或分支时，请使用单个空间的 Git Sync。例如，当私有空间必须单独同步时可使用此方式。

首先从站点的内容映射中移除该空间。然后从该空间配置 Git Sync。

要配置该空间，请按照 [启用 GitHub Sync](/docs/documentation/zh/wen-dang-ji-dai-ma/git-sync/enabling-github-sync.md) 或 [启用 GitLab Sync](/docs/documentation/zh/wen-dang-ji-dai-ma/git-sync/enabling-gitlab-sync.md)。在范围步骤中，选择 **空间 Git Sync**.


---

# 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/wen-dang-ji-dai-ma/git-sync/monorepos.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.
