How to Integrate GitHub with Your Headless CMS
Connect GitHub to your headless CMS so docs, changelogs, examples, and developer portal content can move from editorial review to pull requests, commits, and deployments.
What is GitHub?
GitHub is a developer platform for Git repositories, code review, issues, pull requests, GitHub Actions, packages, and security workflows. Itโs used by individual developers, open-source projects, and companies to collaborate on software and automate delivery. Its core capability is version-controlled collaboration around code and related project assets.
Why integrate GitHub with a headless CMS?
Developer tools teams often split content across two places. Product marketers and docs writers work in an editorial interface, while engineers keep examples, docs sites, changelogs, and release notes in GitHub. Without an integration, someone copies Markdown into a repo, opens a pull request by hand, waits for review, and hopes the deployed docs match what was approved.
Architecture overview
A typical Sanity and GitHub integration starts when an editor publishes a document in Sanity Studio. A webhook with a GROQ filter, for example _type == "docPage" && defined(slug.current), fires only for the document types you want to sync. The webhook sends the document ID to a Sanity Function or your own small API route. That server-side code uses @sanity/client to fetch exactly the fields GitHub needs from the Content Lake with GROQ, including referenced authors, product areas, and release versions. Then it calls GitHubโs REST API through @octokit/rest, commonly PUT /repos/{owner}/{repo}/contents/{path}, to create or update a Markdown, MDX, or JSON file in a repository. If you use protected branches, the same code can commit to a content-sync branch and open a pull request with POST /repos/{owner}/{repo}/pulls. From there, GitHub Actions can build the developer portal, run lint checks, publish a static site, or notify reviewers. The end user sees updated docs, release notes, or API references after the GitHub workflow passes and deploys.
Common use cases
Docs-as-code publishing
Publish approved docs in Sanity Studio, then create MDX commits or pull requests in a GitHub docs repository.
Changelog and release notes
Turn structured release entries into versioned changelog files that ship with the same GitHub release process as your code.
Developer portal data files
Sync navigation, API metadata, SDK links, and example project listings into JSON files consumed by a GitHub-hosted site.
Editorial-to-engineering issues
Create GitHub Issues when content teams flag broken examples, missing SDK coverage, or docs gaps in Sanity Studio.
Step-by-step integration
- 1
Set up GitHub access
Create a GitHub repository for the synced content, or choose an existing docs or developer portal repo. For a simple test, create a fine-grained personal access token with Contents read and write access for that repo. For production, use a GitHub App with repository permissions for Contents, Pull requests, and Issues, then store the token or app credentials as environment variables.
- 2
Install the GitHub and Sanity SDKs
In your Sanity Function, webhook listener, or middleware project, install @octokit/rest and @sanity/client. Youโll use @sanity/client to read structured content from the Content Lake and Octokit to call GitHubโs REST API.
- 3
Model the content in Sanity Studio
Create schemas for the content you want to sync, such as docPage, changelogEntry, apiReference, or exampleProject. Include fields that map cleanly to GitHub files, for example title, slug, body, version, productArea, authors, status, and githubPath.
- 4
Create the publish trigger
Add a Sanity webhook with a GROQ filter such as _type == "docPage" && defined(githubPath). Send a small payload, for example {_id, _type}, to a Sanity Function or webhook endpoint. If you need retries, secrets, and no separate server, use Functions for the sync logic.
- 5
Write to GitHub
Fetch the full document with GROQ, render the fields into Markdown, MDX, or JSON, then call GitHubโs createOrUpdateFileContents API. For protected branches, write to a sync branch and open a pull request instead of committing to main.
- 6
Test the frontend workflow
Publish a test document, confirm the commit or pull request appears in GitHub, and run the related GitHub Actions workflow. Check the deployed docs page, verify links, and test update and delete behavior before turning the integration on for production content.
How Sanity + GitHub works
Build your GitHub integration on Sanity
Sanity gives you the structured content foundation, real-time event system, and flexible APIs to connect editorial workflows with GitHub repositories, pull requests, issues, and Actions.
Start building free โCMS approaches to GitHub
| Capability | Traditional CMS | Sanity |
|---|---|---|
| Content shape for GitHub files | Often exports rendered pages or HTML, so developers have to clean up content before committing Markdown, MDX, or JSON. | Structures content as typed JSON in the Content Lake, with schemas that map directly to repo files, front matter, and data files. |
| Publish-to-repo sync | Usually handled with manual copy and paste, scheduled exports, or custom plugins. | Webhooks and Functions can trigger GitHub commits, pull requests, or issues on content mutations without a separate sync server. |
| Field-level control | Page-oriented content makes it harder to select only the fields a GitHub workflow needs. | GROQ can fetch the exact fields, references, projections, and slices needed for a GitHub API call in one query. |
| Schema changes and review | Content types are often changed in an admin UI, which makes code review and rollback harder. | Sanity Studio schemas are code, so changes to doc models, GitHub paths, and release fields can go through pull request review. |
| Branch and pull request workflows | Usually treats publishing as the final step, not the start of a GitHub review flow. | Functions can apply your GitHub rules, such as committing to content-sync, opening pull requests, and leaving main protected. |
| Content reuse beyond GitHub | Content often stays tied to pages, templates, or one delivery channel. | The same structured back end can feed GitHub, websites, apps, support tools, and AI agents through APIs and Agent Context. |
Keep building
Explore related integrations to complete your content stack.
Sanity + GitLab
Sync structured docs and release content to GitLab repositories, merge requests, and CI pipelines.
Sanity + Linear
Turn content gaps, docs bugs, and launch tasks into Linear issues tied to product workflows.
Sanity + Storybook
Connect component documentation, design guidance, and usage notes from Sanity to Storybook-powered developer references.