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

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

<figure><img src="/files/70b638f926fa9e5564863dd2795211580cd3fa7c" 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 アカウントのリンクを解除（設定で実行）してから、再度ログインして現在のアカウントをリンクできます。

詳しくは [トラブルシューティングページをご覧ください](/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 はセクションをリポジトリの空の内容で置き換えることができます。

初回同期を開始する前に、リポジトリ、ブランチ、方向を確認してください。置き換え先のコンテンツを安全に置き換えられることを確認してください。
{% 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 で変更リクエストをマージすると、その変更が GitHub にコミットされます。GitHub へのコミットは GitBook にも同期されます。
{% endstep %}
{% endstepper %}

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

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

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

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

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

単一のスペースに対して Git Sync を設定するには、同期したいスペースで次をクリックします。 **設定** の横の **Git Sync** の [スペースヘッダー](/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 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-github-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.
