> 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-github-sync.md).

# GitHub Sync を有効にする

GitHub リポジトリを GitBook と同期します

このガイドでは、GitHub 上のリポジトリを使って GitBook サイトを設定する手順を説明します。

<figure><img src="https://4217681718-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2Fgit-blob-6c33061b672738c3e7da914fa50e7424a87179e2%2FGit%20Sync%20-%20GitHub.png?alt=media" alt="A GitBook screenshot showing GitHub Sync configuration options"><figcaption><p>GitHub Sync の設定オプション。</p></figcaption></figure>

{% stepper %}
{% step %}

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

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

{% step %}

### GitHub に接続

同期したいリポジトリにアクセスできる GitHub アカウントを接続します。

{% hint style="warning" %}
次のような **「アカウントが重複している可能性があります」** というエラーメッセージがこの手順で表示された場合、お使いの GitHub アカウントはすでに別の GitBook ユーザーアカウントにリンクされています。

どのアカウントがリンクされているかを識別するには、このセッションからログアウトし、「GitHub でサインイン」方法を使って再度ログインする必要があります。

GitHub に関連付けられている GitBook アカウントがすでに分かっている場合は、そのユーザーアカウントにログインし、GitHub アカウントのリンクを解除（設定で実行）してから、再度ログインして現在のアカウントをリンクできます。

詳しくは、 [トラブルシューティングページ](https://gitbook.com/docs/documentation/ja-gitbook-documentation/docs-as-code/git-sync/troubleshooting.md#potential-duplicated-accounts-when-signing-in).
{% endhint %}
{% endstep %}

{% step %}

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

「 **ソースリポジトリ**」で、ドキュメントを含むリポジトリを選択します。GitBook と同期するブランチを選択します。ブランチが存在しない場合、GitBook は初回同期時に作成します。

{% hint style="info" %}
**リポジトリが見つかりませんか？** リポジトリが一覧に見つからない場合は、 [GitBook GitHub アプリ](https://github.com/apps/gitbook-com) が適切なスコープ（個人アカウント、またはリポジトリがある GitHub 組織）にインストールされていることを確認してください。また、GitBook GitHub アプリで正しいリポジトリへのアクセスを設定していることも確認してください。
{% endhint %}
{% endstep %}

{% step %}

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

初回同期時の正本を選択します。リポジトリの内容で GitBook の内容を置き換える場合は、 **同期方向を反転** を選択してください。

{% hint style="warning" %}
**GitHub → GitBookでは、セクションのコンテンツが置き換えられることがあります。** GitBookは、選択したブランチのコンテンツでセクションを置き換えます。リポジトリが空の場合、または最近の変更リクエストがまだエクスポートされておらず、GitBookより古い内容の場合、そのコンテンツはセクションと公開サイトから失われます。

Git Syncを設定するたびに、再接続する場合や既存の接続を作り直す場合も含め、同期の方向を選択します。同期を開始する前に、リポジトリ、ブランチ、同期の方向を確認してください。GitHub → GitBookを選択する場合は、ブランチの最新のコミットに、直近でマージした変更リクエストが含まれていることを確認してください。

コンテンツが置き換えられた場合は、 [トラブルシューティング](https://gitbook.com/docs/documentation/ja-gitbook-documentation/docs-as-code/git-sync/troubleshooting.md) を参照して復元してください。
{% endhint %}
{% endstep %}

{% step %}

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

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

{% step %}

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

内にある場合は、この設定を使用してください。 **「コンテンツのマッピング」**&#x3067;、各スペースをリポジトリ内のディレクトリに割り当てます。プロジェクトディレクトリからの相対パスには `./` を使用します。リポジトリのルートからのパスには `/` を使用します。新しくリンクしたスペースは自動的に同期されます。
{% endstep %}

{% step %}

### 詳細オプションを確認

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

{% step %}

### サイトを同期

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

{% step %}

### 変更を書き込み、コミット

GitBook で変更リクエストをマージすると、その変更が GitHub にコミットされます。GitHub へのコミットは 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** の横にある [スペースヘッダー](https://gitbook.com/docs/documentation/ja-gitbook-documentation/rifarensu/gitbook-ui.md#space-header)からクリックします。プロバイダーの一覧で、 **GitHub Sync**.

{% hint style="warning" %}
当社の GitHub 連携を支える GitHub アプリは、現在 GitHub Enterprise Server インスタンスをご利用のお客様には提供されていません。
{% endhint %}


---

# 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/ja-gitbook-documentation/docs-as-code/git-sync/enabling-github-sync.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.
