GitBook Git Sync: Practical Setup and Trade‑offs for Engineering Docs
Learn how to connect a Git repository to a GitBook space, map branches and folders, handle editor‑vs‑repo conflicts, and avoid permission mismatches — plus the trade‑offs you must verify before relying on two‑way sync.
14 Nov 2025, 22:18 UTC

The problem: docs live in two places
Engineering teams often keep architecture decisions, API references, and runbooks as Markdown files inside the same repository that holds the code. At the same time, product managers and technical writers prefer the GitBook web editor for its live preview and collaboration features. The result is a classic split‑brain: changes made in the repo don’t appear in GitBook, and edits made in GitBook never make it back to version control.
Thesis: Git‑backed spaces work, but only with deliberate configuration
GitBook can treat a repository branch (or a sub‑folder inside it) as the source of truth for a space. When the integration is set up correctly, a push to the mapped branch triggers a sync that creates or updates pages automatically. The catch is that the sync direction, conflict handling, and permission model are not symmetric by default, so you must decide early whether you want a one‑way import or a true two‑way round‑trip.
1. Connecting a repository and mapping content
In the GitBook admin UI, open Space Settings → Integrations → Git Sync. Choose your Git provider (GitHub, GitLab, Bitbucket) and authorize the app. Then pick a repository, a branch (commonly main or a dedicated docs branch), and optionally a folder path such as docs/. Only files under that path become pages; everything else is ignored, which prevents unrelated code changes from firing documentation builds.
Worked example – adding a new architecture page:
# Run locally in a clone of the repo (requires write access)
git checkout -b add-architecture-doc
echo -e "# Service Architecture\n\nThis page describes the high‑level components." > docs/architecture.md
git add docs/architecture.md
git commit -m "Add architecture overview"
git push origin add-architecture-doc
# Open a PR targeting main; after merge the GitBook sync runs (usually within a minute)
After the merge, navigate to the GitBook space – the new page Service Architecture should appear under the same hierarchy as the folder structure. If it doesn’t, check the sync log in Space Settings → Git Sync → Activity for errors such as missing front‑matter or unsupported custom components.
2. Conflict handling: editor vs. repository
GitBook’s editor writes changes back to the repository only when two‑way sync is explicitly enabled (often a paid‑plan feature). With the default one‑way import, an edit made in the web UI creates a local draft that is overwritten on the next repository sync. If two‑way sync is on, simultaneous edits on the same page in GitBook and in a pull request generate a Git conflict that must be resolved manually – GitBook will surface a “Sync conflict” banner and pause further imports until the conflict is cleared.
Practical rule: designate a single source of truth per page. For engineering‑owned pages, keep the repo as the authority and restrict GitBook editing to comments or suggestions. For marketing‑owned pages, enable two‑way sync but lock the corresponding files in the repo (e.g., via CODEOWNERS) so only the docs team can merge.
3. Permissions don’t mirror automatically
Repository read/write rights and GitBook space roles are independent. A developer with push access to main may still need an explicit Editor or Admin role in the GitBook space to see the sync status or to resolve conflicts. Conversely, a technical writer granted Editor in GitBook cannot push to the repo unless they also have write permission there. Align the two by creating a GitBook team that mirrors the repo’s CODEOWNERS group and assigning the same members.
4. Limitations you should verify
- Sync direction – Confirm in the admin UI whether the current plan supports pushing editor changes back to Git. Some tiers only import.
- Custom components – GitBook‑specific blocks (tabs, API explorers, custom React components) are stored as JSON in the space. When content comes from plain Markdown, those blocks are lost or rendered as raw HTML.
- Deletion propagation – In two‑way mode, deleting a page in GitBook removes the Markdown file on the next sync. In one‑way mode, the file stays in the repo but the page disappears from the site. Test both behaviours in a sandbox space before adopting.
- Large monorepos – Sync scans the entire mapped path on each push. Use a narrow folder filter (e.g.,
docs/engineering/) and consider a dedicated docs branch to keep sync latency low.
Actionable next step
Create a throwaway GitBook space, connect it to a test repository, and enable the narrowest folder mapping you need. Push a few Markdown files, edit one in the web UI, and observe the activity log. Verify that the sync direction matches your workflow, that conflicts surface clearly, and that custom components behave as expected. Once the sandbox behaves predictably, promote the same configuration to your production space and document the agreed‑upon source‑of‑truth policy in your contribution guide.