> 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 リポジトリと同期したいセクションで、をクリックします **セットアップ** の横の **Git Sync** の [セクションヘッダー](/docs/documentation/ja-gitbook-documentation/rifarensu/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/docs-as-code/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/kontentsuwosuru/version-control.md#roll-back-to-a-previous-version).

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

同期前のリビジョンが利用できない場合、またはロールバックを完了できない場合は、 [GitBook サポートにお問い合わせください](broken://pages/55ca09da2fc64db3d290bfa3cf9175afa45c2bdc).

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

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

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/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.
