> 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 リポジトリと同期したいセクションで、次をクリックしてください **セットアップ** の横の **Git Sync** の [セクションヘッダー](/docs/documentation/ja-gitbook-documentation/rifarensu/gitbook-ui.md#space-header)。プロバイダー一覧から、をクリックします **GitLab Sync**、そしてクリック **設定**.

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

### API アクセストークンを生成して入力してください

GitLab のユーザー設定で API アクセストークンを生成できます。

{% hint style="info" %}
GitLab には 2 種類のアクセストークンがあります: Project と Personal。連携を機能させるには Personal トークンを使用する必要があることに注意してください。これは GitLab のユーザー設定メニューから生成できます。
{% endhint %}

トークンに対して以下のアクセス権を有効にしてください:

* `api`
* `read_repository`
* `write_repository`

作成するトークンに特定のロールも付与されている場合は、それに `Maintainer` または `管理` ロールが割り当てられていることも確認してください。

その後、GitLab 連携を設定するときに、そのトークンを API アクセストークン欄に貼り付けることができます。

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

GitBook コンテンツと同期し続けたいリポジトリを選択してください。

{% hint style="info" %}
**リポジトリが見つかりませんか？** API トークンを作成するときに、正しい権限を設定したことを確認してください。
{% endhint %}

正しいリポジトリを選択したら、コミットをプッシュし、そこから同期するブランチを選びます。

{% hint style="warning" %}
多くの GitLab リポジトリでは、 `main` ブランチが自動的に保護対象として設定されている場合があります。その場合は、コンテンツを同期するための特定のブランチを追加することをおすすめします。その後、これを `main` にマージして、保護を維持できます。
{% endhint %}

### 初回同期を実行する

初めて同期するときは、次の 2 つの方向のいずれかで同期するオプションがあります:

1. GitBook -> GitLab では、セクションのコンテンツを同期します **です** 選択したブランチへ同期します。これは、空のリポジトリから始めて GitBook のコンテンツをすばやく取り込みたい場合に最適です。
2. GitLab -> GitBook では、セクションのコンテンツを同期します **から** 選択したブランチから同期します。これは、リポジトリに既存の Markdown コンテンツがあり、それを GitBook に取り込みたい場合に最適です。

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

これで準備完了です。セクションが [ライブ編集](/docs/documentation/ja-gitbook-documentation/gong-tong-zuo-ye/live-edits.md) モードでは、ライブ編集は現在ロックされています。これにより、GitBook は、チームの誰かが 1 件の [変更リクエスト](/docs/documentation/ja-gitbook-documentation/gong-tong-zuo-ye/change-requests.md) を GitBook でマージしたときに、コンテンツを確実にリポジトリへ同期できるようになります。

GitBook で編集すると、変更リクエストがマージされるたびに、選択した GitLab ブランチにコミットが作成されます。

GitLab にコミットすると、すべてのコミットが履歴コミットとして GitBook のセクションに同期されます。


---

# 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.
