> 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/ja-gitbook-documentation/docs-as-code/git-sync/enabling-gitlab-sync.md).

# GitLab Sync を有効にする

このガイドでは、GitLab 上のリポジトリを使って GitBook サイトをセットアップする手順を説明します。

<figure><img src="/files/66fc20ece1e5ea93cfc05faa10b2c64b70325e47" alt="A GitBook screenshot showing GitLab Sync configuration options"><figcaption><p>GitLab Sync の設定オプション。</p></figcaption></figure>

{% stepper %}
{% step %}

### サイトで Git Sync を開く

サイトから、サイドバーで Git Sync を開きます。
{% endstep %}

{% step %}

### GitLab を接続

GitLab のユーザー設定で Personal Access Token を作成します。を有効にします `api`, `read_repository`を読み取り、 `write_repository`その後、トークンを GitBook に入力します。

{% hint style="info" %}
トークンにロールがある場合は、選択してください `メンテナー` または `管理`.
{% endhint %}
{% endstep %}

{% step %}

### リポジトリとブランチを選択

次の項目の下で **ソースリポジトリ**、ドキュメントが含まれているリポジトリを選択します。GitBook が同期するブランチを選択してください。そのブランチが存在しない場合、GitBook は初回同期時に作成します。

{% hint style="info" %}
**リポジトリが見つかりませんか？** Personal Access Token に必要なスコープとリポジトリアクセスがあることを確認してください。
{% endhint %}

{% hint style="warning" %}
もしあなたの `main` ブランチが保護されている場合は、Git Sync 用に別のブランチを選択してください。そのブランチを次へマージできます `main` 保護を維持したまま。
{% endhint %}
{% endstep %}

{% step %}

### 初回同期の方向を選択

初回同期のソース・オブ・トゥルースを選択します。 **方向を入れ替え** リポジトリの内容で GitBook の内容を置き換える場合。

{% hint style="warning" %}
**GitLab → GitBook では、サイトのコンテンツが置き換えられる場合があります。** 同期を開始する前に、リポジトリ、ブランチ、方向を確認してください。置き換えても安全な送信先コンテンツであることを確認してください。
{% endhint %}
{% endstep %}

{% step %}

### プロジェクトディレクトリを設定

ドキュメントがサブディレクトリにある場合は、 **プロジェクトディレクトリ**の下に入力してください。GitBook はサイトの `docs.yaml` ファイルをこのディレクトリに保存します。ドキュメントが [monorepo](/docs/documentation/ja-gitbook-documentation/docs-as-code/git-sync/monorepos.md).
{% endstep %}

{% step %}

### スペースをマッピング

次の項目の下で **コンテンツのマッピング**で、各スペースをリポジトリ内のディレクトリに割り当てます。 `./` プロジェクトディレクトリからの相対パスには `/` リポジトリのルートからのパスには
{% endstep %}

{% step %}

### を使用します。新しくリンクされたスペースは自動的に同期されます。

必要に応じて、エージェント指示ファイル、コミットメッセージテンプレート、またはフォークのプレビューを設定します。
{% endstep %}

{% step %}

### サイトを同期

クリックして **同期** して初回同期を開始します。
{% endstep %}

{% step %}

### 書き込みとコミット

GitBook で変更リクエストをマージして、その変更を GitLab にコミットします。GitLab へのコミットは GitBook に同期されて戻ります。
{% endstep %}
{% endstepper %}

#### サイト全体の Git Sync からスペースを除外する

サイトの Git Sync のコンテンツマッピングで、除外したいスペースの横にある削除アイコンをクリックします。その後、そのスペースから Git Sync を設定できます。

サイトにすでに Git Sync がある場合、GitBook はスコープを選択するよう求めます:

* サイト全体の Git Sync にスペースを追加するには、サイトのリポジトリとブランチを選択します。
* Space Git Sync を設定するには、独立したリポジトリとブランチを選択します。

サイトで Git Sync を使用していない場合、GitBook はそのスペースに対して個別に Git Sync を設定します。

単一のスペースに Git Sync を設定するには、同期したいスペースで **セットアップ** の横にある **Git Sync** の [スペースヘッダー](/docs/documentation/ja-gitbook-documentation/rifarensu/gitbook-ui.md#space-header)をクリックします。プロバイダー一覧から **GitLab 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/ja-gitbook-documentation/docs-as-code/git-sync/enabling-gitlab-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.
