> 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/guides/editing-and-publishing-documentation/how-to-sync-your-entire-docs-site-with-a-git-repository.md).

# How to sync your entire docs site with a Git repository

Git Sync connects your repository to a published docs site. Your repo stays the source of truth, but you can now organize and manage all of your GitBook spaces under one unified Git Sync configuration — making it much easier to keep a multi-space site in sync with a single repository.

{% hint style="info" %}
Before you start, make sure you know:

* Which spaces are currently synced
* Which site each space should belong to
* The repo, branch, and project directory for each space
* Whether any space should stay hidden or in draft during the move
  {% endhint %}

{% stepper %}
{% step %}

### **Create or open your site**

Open the site in GitBook that you plan on syncing with GitHub or GitLab. If you're consolidating multiple spaces into one site, it's a good idea to create the site structure first, so each space has a clear place in your navigation before you connect anything.

You can review and reorganize your structure at any time from your site's dashboard, in the **Structure** section of the **Settings** tab.
{% endstep %}

{% step %}

### **Initiate Git Sync**

From your site's dashboard, open the **Git Sync** panel. Here you'll authorize your Git provider and choose the repository and branch you want to sync with your site.

{% tabs %}
{% tab title="GitHub" icon="github" %}
Install the [GitBook app](https://github.com/apps/gitbook-com/installations/select_target) on GitHub before connecting your repository. Grant the app access to selected repositories or all repositories.
{% endtab %}

{% tab title="GitLab" icon="gitlab" %}
Create a personal access token in GitLab. In GitLab, navigate to **Settings** > **Access Tokens**. Enable the following token scopes:

* `api`
* `read_repository`
* `write_repository`

In GitBook, enter the token, then click **Authenticate**.
{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

### **Verify your space mapping**

Once Git Sync is connected, review how each space in your site maps to a directory in your repository, and make sure everything points where you expect.

{% hint style="warning" %}
Setting up site-level Git Sync will override any existing space-based configuration. If you'd like to keep syncing certain spaces individually, remove them from the site-level configuration here.
{% endhint %}
{% endstep %}

{% step %}

### **Start your sync**

When you're happy with the mapping, click **Sync** to start syncing. GitBook will connect your repository to the site and begin keeping the two in sync.
{% endstep %}

{% step %}

### **Sync individual spaces (optional)**

If some spaces should sync to a separate repository, you can still configure them individually. Open the **Git Sync** panel from the space header of each space you want to sync on its own, and connect it to its own repo, branch, and directory.
{% endstep %}

{% step %}

### **Verify and test**

That's it! Explore your new setup to make sure everything is working as expected. Make a small change in your repository and check that the commit comes through to your site — and, if you're syncing in both directions, edit a page in GitBook and confirm the change lands back in your repo.
{% endstep %}
{% endstepper %}

[**→ How to find & replace or batch change with Git Sync**](/docs/guides/editing-and-publishing-documentation/find-and-replace-or-make-batch-changes-across-your-gitbook-docs-with-git-sync.md)

[**→ Discover more about Git Sync on our website**](https://www.gitbook.com/solutions/git-sync)

[**→ Read the Git Sync documentation**](/docs/docs-as-code/git-sync.md)


---

# 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/guides/editing-and-publishing-documentation/how-to-sync-your-entire-docs-site-with-a-git-repository.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.
