# GitHub 同期を有効にする

### 始める

GitHub リポジトリと同期したいスペースで、 [スペースヘッダー](/docs/documentation/ja-gitbook-documentation/rissu/gitbook-ui.md#space-header) 右上の **設定**を開き、 **GitHub Sync**.

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

### GitHub で認証する

初めて GitHub Sync を設定し、まだ GitHub アカウントを連携していない場合は、Git Sync の設定を始めるときに連携を求められます。すでにアカウントを連携している場合でも、GitHub 経由での認証が必要になることがあります。

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

どのアカウントが連携されているかを確認するには、このセッションからログアウトし、GitHub でサインインする方法でログインし直す必要があります。

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

詳細は [トラブルシューティングページ](/docs/documentation/ja-gitbook-documentation/getting-started/git-sync/troubleshooting.md#potential-duplicated-accounts-when-signing-in).
{% endhint %}

### GitBook アプリを GitHub アカウントにインストールする

まだ行っていない場合は、 [GitBook アプリ](https://github.com/apps/gitbook-com) を GitHub アカウントに追加するよう促すメッセージが表示されます。

GitHub のポップオーバーの指示に従い、必要に応じて GitBook に特定のリポジトリ権限を付与するか、すべてのリポジトリへのアクセスを許可してください。

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

GitBook のコンテンツと同期したいアカウントとリポジトリを選択してください。

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

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

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

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

1. GitBook -> GitHub は、スペースのコンテンツを **に** 選択したブランチへ同期します。空のリポジトリから始める場合や、GitBook のコンテンツをすぐに取り込みたい場合に最適です。
2. GitHub -> GitBook は、スペースのコンテンツを **から** 選択したブランチへ同期します。リポジトリに既存の Markdown コンテンツがあり、それを GitBook に取り込みたい場合に最適です。

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

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

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

GitHub にコミットすると、すべてのコミットが履歴コミットとして GitBook スペースに同期されます。

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


---

# Agent Instructions: 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:

```
GET https://gitbook.com/docs/documentation/ja-gitbook-documentation/getting-started/git-sync/enabling-github-sync.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
