# Git Sync

Keep a docs site and folders of Markdown on GitHub or GitLab in step, in both directions.

Git Sync connects a docs site to a branch of a GitHub repository or a GitLab project, and each of its
spaces to a folder on it. Writers work in the editor, engineers work in pull requests, and both see the
same pages.

```mermaid
flowchart LR
  E[Editor] -- publish --> S[Space]
  S -- commit --> G[(Git branch)]
  G -- push --> S
  S -- conflicting push --> CR[Change request]
```

## How it works

- **Docsheaf → Git.** Every new published version of the space becomes a commit on the branch, authored
  with the name of whoever made it. Only files that changed are written.
- **Git → Docsheaf.** Every push to the branch is read back. If nobody changed the space in Docsheaf since
  the last sync, the push is published directly. If both sides changed — or the space requires review —
  the push opens a **change request**, which merges like any other, with conflict resolution.
- Pushes that only touch files outside a space's folder are ignored, and Docsheaf's own commits never come back
  as changes.

## What's in the repository

The same files as the [Markdown export](import-and-export#export): one `.md` file
per page with front matter, `SUMMARY.md` as the table of contents, `.docsheaf.yaml`, and uploads in
`.docsheaf/assets/`. Repositories laid out for GitBook (with `.gitbook.yaml`) work as they are. See
[Content configuration](git-sync/content-configuration).

## Commit statuses

When a push opens a change request, Docsheaf adds a **Docsheaf** status to the commit on GitHub or GitLab:
waiting for review, approved, changes requested, merged or closed — each linking to the change request.

<table data-view="cards"><thead><tr><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody>
<tr><td><strong>Enable Git Sync</strong></td><td>Connect GitHub or GitLab in a few steps.</td><td><a href="git-sync/enable-git-sync">git-sync/enable-git-sync</a></td><td></td></tr>
<tr><td><strong>Content configuration</strong></td><td>SUMMARY.md, front matter and .docsheaf.yaml.</td><td><a href="git-sync/content-configuration">git-sync/content-configuration</a></td><td></td></tr>
<tr><td><strong>Troubleshooting</strong></td><td>When a sync doesn't do what you expect.</td><td><a href="git-sync/troubleshooting">git-sync/troubleshooting</a></td><td></td></tr>
</tbody></table>
