Explore how adaptive content transforms your docs into a dynamic, tailored experience for every user.
Read the docs
LogoLogo
ProductPricingLog inSign up
  • Documentation
  • Developers
  • Guides
  • Changelog
  • Help Center
  • Getting Started
    • Developer Documentation
    • Quickstart
    • Development
    • Publishing
  • Integrations
    • Introduction
    • Using the CLI
    • Configuration
    • ContentKit
      • Component reference
    • Integration runtime
  • Client library
  • Guides
    • Creating a custom unfurl action
    • Creating interactive blocks
    • Referencing your integration in Markdown
    • Working with HTTP requests
    • Using the CLI in CI/CD
  • GitBook API
    • Introduction
    • Authentication
    • API reference
      • Organizations
        • Organization members
        • Organization invites
        • Organization AI ask
      • Docs sites
        • Site share links
        • Site structure
        • Site auth
        • Site preview
        • Site customization
        • Site spaces
        • Site sections
        • Site section groups
        • Site redirects
        • Site MCP servers
        • Site ads
        • Site users
        • Site insights
        • Site AI ask
      • Collections
        • Collection users
        • Collection teams
      • Spaces
        • Space content
        • Space comments
        • Space embeds
        • Space users
        • Space teams
        • Space integrations
        • Git
      • Change requests
        • Change request content
        • Change request contributors
        • Change request reviewers
        • Change request comments
      • Translations
        • Glossary
      • Integrations
      • URLs
      • OpenAPI
        • OpenAPI spec versions
      • Conversations
      • Custom fonts
      • Subdomains
      • Users
      • Teams
        • Team members
      • SSO
      • Storage
      • Custom hostnames
      • System info
    • Rate limiting
    • Pagination
    • Errors
  • Marketplace
    • Overview
    • Submit your app for review
  • Resources
    • Concepts
    • Changelog
    • ContentKit playground
    • GitHub examples
Powered by GitBook
On this page
  1. GitBook API
  2. API reference
  3. Spaces

Git

Connect Git repositories to your space for seamless version control.

Was this helpful?

LogoLogo

Resources

  • Showcase
  • Enterprise
  • Status

Company

  • Careers
  • Blog
  • Community

Policies

  • Subprocessors
  • Terms of Service
CtrlK
  • POSTImport a Git repository
  • POSTExport the to a Git repository
  • GETGet space Git info
  • DELETERemove the legacy Git Sync installation from the space to be able to upgrade it to use the new Git integrations

Was this helpful?

Manage the linkage between your GitBook space and external Git repositories, enabling commits, merges, and pull requests directly tied to your documentation.

Import a Git repository

post
Authorizations
Path parameters
spaceIdstringRequired

The unique id of the space

Body
urlstringRequired

URL of the Git repository to import. It can contain basic auth credentials.

refstringRequired

Git ref to import in the format "refs/heads/main"

repoCacheIDstringOptional

Unique identifier to use to cache the Git repository across multiple operations.

repoTreeURLstringOptional

URL to use as a prefix for external file references.

repoCommitURLstringOptional

URL to use as a prefix for the commit URL.

repoProjectDirectorystringOptional

Path to a root directory for the project in the repository.

timestampstring · date-timeOptional

The timestamp of the event that triggered this import. It ensures that Git sync import and export operations are executed in the same order on GitBook and on the remote repository.

forcebooleanOptional
standalonebooleanOptional

If true, the import will generate a revision without updating the space primary content.

Responses
204

Operation to import the repository has been started.

post
POST /v1/spaces/{spaceId}/git/import HTTP/1.1
Host: api.gitbook.com
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: application/json
Accept: */*
Content-Length: 237

{
  "url": "text",
  "ref": "text",
  "repoCacheID": "text",
  "repoTreeURL": "text",
  "repoCommitURL": "text",
  "repoProjectDirectory": "text",
  "timestamp": "2025-08-26T23:21:56.168Z",
  "force": true,
  "standalone": true,
  "gitInfo": {
    "provider": "github",
    "url": "text"
  }
}
204

Operation to import the repository has been started.

No content

Export the to a Git repository

post
Authorizations
Path parameters
spaceIdstringRequired

The unique id of the space

Body
urlstringRequired

URL of the Git repository to export to. It can contain basic auth credentials.

refstringRequired

Git ref to push the commit to in the format "refs/heads/main"

commitMessagestringRequired

Message for the commit generated by the export

repoCacheIDstringOptional

Unique identifier to use to cache the Git repository across multiple operations.

repoTreeURLstringOptional

URL to use as a prefix for external file references.

repoCommitURLstringOptional

URL to use as a prefix for the commit URL.

repoProjectDirectorystringOptional

Path to a root directory for the project in the repository.

timestampstring · date-timeOptional

The timestamp of the event that triggered this export. It ensures that Git sync import and export operations are executed in the same order on GitBook and on the remote repository.

forcebooleanOptional
Responses
204

Operation to export the space has been started.

post
POST /v1/spaces/{spaceId}/git/export HTTP/1.1
Host: api.gitbook.com
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: application/json
Accept: */*
Content-Length: 242

{
  "url": "text",
  "ref": "text",
  "commitMessage": "text",
  "repoCacheID": "text",
  "repoTreeURL": "text",
  "repoCommitURL": "text",
  "repoProjectDirectory": "text",
  "timestamp": "2025-08-26T23:21:56.168Z",
  "force": true,
  "gitInfo": {
    "provider": "github",
    "url": "text"
  }
}
204

Operation to export the space has been started.

No content

Get space Git info

get

Get metadata about the Git Sync provider currently set up on the space.

Authorizations
Path parameters
spaceIdstringRequired

The unique id of the space

Responses
200

The Git Sync info for the space

application/json
404

No Git provider currently set up on the space

application/json
get
GET /v1/spaces/{spaceId}/git/info HTTP/1.1
Host: api.gitbook.com
Authorization: Bearer YOUR_SECRET_TOKEN
Accept: */*
{
  "repoName": "text",
  "installationProvider": "github",
  "integration": "text",
  "url": "text",
  "updatedAt": "2025-08-26T23:21:56.168Z"
}

Remove the legacy Git Sync installation from the space to be able to upgrade it to use the new Git integrations

delete
Authorizations
Path parameters
spaceIdstringRequired

The unique id of the space

Responses
204

The legacy Git installation was already removed

205

The legacy Git installation was successfully removed

delete
DELETE /v1/spaces/{spaceId}/git/legacy-installation HTTP/1.1
Host: api.gitbook.com
Authorization: Bearer YOUR_SECRET_TOKEN
Accept: */*

No content