> 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 同期を有効にする

このガイドでは、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` ファイルをこのディレクトリに保存します。ドキュメントが次の場所にある場合は、この設定を使用してください [モノレポ](/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 に追加するには、サイトのリポジトリとブランチを選択します。
* スペースの Git Sync を設定するには、個別のリポジトリとブランチを選択します。

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

1 つのスペースに 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.
