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

# Enabling GitHub Sync

### Getting started

In the section you want to sync with your GitHub repo, click **Set up** next to **Git Sync** in the [section header](/docs/resources/gitbook-ui.md#space-header). From the provider list, click **GitHub Sync**.

<figure><img src="/files/6l7iXXhAVJ8FHxjMv5pe" alt="A GitBook screenshot showing GitHub Sync configuration options"><figcaption><p>GitHub Sync configuration options.</p></figcaption></figure>

### Authenticate with GitHub

If you’re setting up GitHub Sync for the first time and haven’t already linked a GitHub account, you’ll be prompted to do that when you begin configuring Git Sync. If you’ve already linked your account, you may still need to authenticate via GitHub.

{% hint style="warning" %}
If you see a **'Potential duplicated accounts'** error message at this step, this means your GitHub account is already linked with another GitBook user account.

To help you identify which accounts are linked, you will have to log out from this session and log in using the sign-in with GitHub method.

If you already know your GitBook account associated with GitHub you can log into that user account and unlink your GitHub account (done in settings) before logging back in and linking your current account.

Read more on our [troubleshooting page](/docs/getting-started/git-sync/troubleshooting.md#potential-duplicated-accounts-when-signing-in).
{% endhint %}

### Install the GitBook app to your GitHub account

If you haven’t already done so, you’ll see a prompt to add the [GitBook app](https://github.com/apps/gitbook-com) to your GitHub account.

Follow the instructions in the GitHub popover and either give GitBook specific repository permissions, or allow access to all repositories, depending on your needs.

### Select a repository and branch

Select the account and repository you want to keep in sync with your GitBook content.

{% hint style="info" %}
**Can’t see your repository?** If you can't find your repository in the list, make sure that you've installed the [GitBook GitHub app](https://github.com/apps/gitbook-com) in the right scope (i.e. your personal account or the GitHub org where the repository lives). You should also check that you’ve configured the correct repository access in the GitBook GitHub app.
{% endhint %}

Once you’ve selected the correct repository, choose which branch you want commits to be pushed to and synced from.

### Perform an initial sync

For the initial sync, the selected source is authoritative. The initial sync can replace existing content in its destination.

Choose one of these directions:

1. **GitBook → GitHub:** GitBook is the source of truth. Use this direction only when the selected branch can receive your section’s content.
2. **GitHub → GitBook:** The selected GitHub branch is the source of truth. Use this direction only when your section can receive that branch’s content.

{% hint style="warning" %}
**GitHub → GitBook can replace your section’s content.** If you select an empty repository, GitBook can replace your section with the repository’s empty content.

Before you start the initial sync, confirm the repository, branch, and direction. Make sure the destination content is safe to replace.
{% endhint %}

When you’re ready, start the initial sync.

### If you chose the wrong direction

Git Sync operations appear in the section’s **Version history**. Locate the revision immediately before the Git Sync operation, then click **Rollback** to restore the prior section content.

For detailed steps, see [Version control](/docs/creating-content/version-control.md#roll-back-to-a-previous-version).

Disconnecting Git Sync stops future synchronization. It does not restore content automatically.

If the pre-sync revision is unavailable or you can’t complete the rollback, [contact GitBook Support](/docs/resources/support.md).

### Write and commit

You’re good to go. You’ll notice that if your section was in [live edit](/docs/collaboration/live-edits.md) mode, live edits are now locked. This allows us to reliably sync content to your repository when someone in your team merges a [change request](/docs/collaboration/change-requests.md) in GitBook.

When you edit on GitBook, every change request merge will result in a commit to your selected GitHub branch.

When you commit to GitHub, every commit will be synced to your GitBook section as a history commit.

{% hint style="warning" %}
The GitHub app that powers our GitHub integration is currently not available to customers on GitHub Enterprise Server instances.
{% 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/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.
