Developer Tools8 min read

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.

Published April 30, 2026
01 โ€” Overview

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.


02 โ€” The case for integration

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.


03 โ€” Architecture

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.


04 โ€” Use cases

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.


05 โ€” Implementation

Step-by-step integration

  1. 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. 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. 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. 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. 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. 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.



07 โ€” Why Sanity

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 โ†’

08 โ€” Comparison

CMS approaches to GitHub

CapabilityTraditional CMSSanity
Content shape for GitHub filesOften 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 syncUsually 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 controlPage-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 reviewContent 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 workflowsUsually 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 GitHubContent 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.

09 โ€” Next steps

Keep building

Explore related integrations to complete your content stack.

Ready to try Sanity?

See how Sanity's Content Operating System powers integrations with GitHub and 200+ other tools.