> 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 サイトをセットアップする手順を説明します。

<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` ファイルをこのディレクトリに保存します。ドキュメントが [monorepo](/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 にスペースを追加するには、サイトのリポジトリとブランチを選択します。
* Space 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.
