GitBook Repository Sync: Direction, Scopes, and Markdown Parity
Connect GitBook to GitHub or GitLab with the right sync direction, narrow OAuth scopes, and a Markdown parity check before your team relies on it.
22 Jul 2025, 14:53 UTC

Start with the direction, not the integration
Your team writes product documentation in GitBook, while engineers propose changes through pull requests in the repository that holds the code. If you connect GitBook to that repository without deciding which side wins, edits made in the GitBook editor can overwrite repository commits, and repository pushes can silently replace pages your writers just published. The practical takeaway is to treat the connection as one-way unless you have tested conflict handling, scoped the OAuth installation to a single repository, and verified that your Markdown renders the same on both sides before announcing the setup to the team.
This applies to modern GitBook SaaS, not the legacy open-source GitBook CLI. Feature names and behavior do not carry over between the two.
Compare the two sync directions
GitBook can connect to a GitHub or GitLab repository so Markdown files in the repository act as the documentation source. You choose the direction when configuring the integration:
| Direction | Best for | Main risk |
|---|---|---|
| GitBook to repository | Teams that edit primarily in the GitBook UI | Commits created by the sync can overwrite manual repository changes |
| Repository to GitBook | Documentation as code, where pull requests are the source of truth | Edits made in the GitBook editor may be overwritten on the next sync |
| Bidirectional | Teams that genuinely edit in both places | Merge conflicts and lost edits if both sides change the same page |
Page ordering is controlled by GitBook's summary configuration or UI drag-and-drop, not strictly by file names or directory order. A repository rename or move will not automatically reorder pages in GitBook.
Scope the OAuth installation before approving it
The connection uses OAuth and requires installing the GitBook app on the target repository with repository-level access. Review the authorization screen to confirm the requested scopes before approving. Where possible, install the app on a single test repository rather than granting access to all repositories, and use a dedicated service account or fine-grained token if your provider supports it.
Webhooks and activity logs can audit sync events and trigger downstream work such as link checks. Treat these logs as your primary evidence that a change propagated, not the absence of an error message.
Worked example: connect a test repository
Create a disposable GitBook space and a test repository before touching production documentation. The following commands run on your local workstation and require write access to the target repository.
# Replace placeholders with your own values.
git clone https://github.com/your-org/test-docs-repo.git
cd test-docs-repo
mkdir -p docs
echo "# Getting started" > docs/index.md
git add docs/index.md
git commit -m "Add initial documentation"
git push origin main
Expected check: the new file appears on GitHub. Then, in GitBook, open the space settings, choose the GitHub or GitLab integration, install the app, select only the test repository, and set the sync direction to "Repository changes overwrite GitBook." After the sync runs, the page should appear in GitBook.
Next, make a small edit directly in the GitBook editor. If the direction is repository-to-GitBook, that edit should be discarded on the next repository sync. If you enabled GitBook-to-repository, the edit should create a commit in the test repository. Inspect the commit attribution and resulting content to confirm which side won.
Limitations: Markdown parity and plan features
GitBook-specific Markdown extensions may not round-trip identically when edited directly in the repository. Callouts, custom components, or front matter can render differently in GitBook than in a local Markdown preview. Compare a page using front matter in GitBook against a local preview before relying on the sync for structured content.
Custom domains, SAML SSO, and advanced analytics are typically separate plan features and are not part of core sync behavior. Pricing, sync limits, and provider support change over time, so confirm current plan details before procurement.
Verify before rolling out
- Create a disposable GitBook space and link a test repository.
- Make an edit in GitBook and a conflicting edit in the repository, then inspect commit attribution and resulting content.
- Review the OAuth authorization screen to confirm requested repository scopes before approving the app.
- Compare rendering of a page using front matter and summary ordering in GitBook versus a local Markdown preview.
If the sync direction proves wrong, disconnecting the integration stops further changes. Reconnect with the opposite direction after you have documented the decision for your team.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.