> 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/getting-started/git-sync/enabling-github-sync.md).

# GitHub Sync を有効にする

### はじめに

GitHub リポジトリと同期したいセクションで、 **設定する** の横の **Git Sync** の [セクション見出し](/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 %}

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

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

初回同期では、選択したソースが正と見なされます。初回同期によって、同期先にある既存のコンテンツが置き換えられる場合があります。

次のいずれかの方向を選択してください：

1. **GitBook → GitHub:** GitBook が正本です。この方向は、選択したブランチがセクションのコンテンツを受け取れる場合にのみ使用してください。
2. **GitHub → GitBook:** 選択した GitHub ブランチが正本です。この方向は、セクションがそのブランチのコンテンツを受け取れる場合にのみ使用してください。

{% hint style="warning" %}
**GitHub → GitBook ではセクションのコンテンツが置き換えられる場合があります。** 空のリポジトリを選択した場合、GitBook はそのリポジトリの空のコンテンツでセクションを置き換えることがあります。

初回同期を始める前に、リポジトリ、ブランチ、方向を確認してください。同期先のコンテンツが安全に置き換えられることを確かめてください。
{% endhint %}

準備ができたら、初回同期を開始します。

### 間違った方向を選んだ場合

Git Sync の操作はセクションの **履歴**に表示されます。Git Sync 操作の直前のリビジョンを見つけてから、 **ロールバック** をクリックして以前のセクションコンテンツを復元します。

詳細な手順については、 [バージョン管理](/docs/documentation/ja-gitbook-documentation/creating-content/version-control.md#roll-back-to-a-previous-version).

Git Sync を切断しても、今後の同期が停止するだけです。コンテンツは自動では復元されません。

同期前のリビジョンが利用できない場合、またはロールバックを完了できない場合は、 [GitBook サポートにお問い合わせください](https://gitbook.com/docs/help-center/further-help/how-do-i-contact-support).

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

これで準備完了です。セクションが [ライブ編集](/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
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/getting-started/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.
