Git

Connect Git repositories to your space for seamless version control.

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.

gitInfoobjectoptional

Optional metadata to store on the space about the Git provider

Responses
curl -L \
  --request POST \
  --url 'https://api.gitbook.com/v1/spaces/{spaceId}/git/import' \
  --header 'Authorization: Bearer YOUR_SECRET_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
    "url": "text",
    "ref": "text",
    "repoCacheID": "text",
    "repoTreeURL": "text",
    "repoCommitURL": "text",
    "repoProjectDirectory": "text",
    "timestamp": "2025-04-12T21:04:01.285Z",
    "force": true,
    "standalone": true,
    "gitInfo": {
      "provider": "github",
      "url": "text"
    }
  }'

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
gitInfoobjectoptional

Optional metadata to store on the space about the Git provider

Responses
curl -L \
  --request POST \
  --url 'https://api.gitbook.com/v1/spaces/{spaceId}/git/export' \
  --header 'Authorization: Bearer YOUR_SECRET_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
    "url": "text",
    "ref": "text",
    "commitMessage": "text",
    "repoCacheID": "text",
    "repoTreeURL": "text",
    "repoCommitURL": "text",
    "repoProjectDirectory": "text",
    "timestamp": "2025-04-12T21:04:01.285Z",
    "force": true,
    "gitInfo": {
      "provider": "github",
      "url": "text"
    }
  }'

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
curl -L \
  --url 'https://api.gitbook.com/v1/spaces/{spaceId}/git/info' \
  --header 'Authorization: Bearer YOUR_SECRET_TOKEN'
{
  "repoName": "text",
  "installationProvider": "github",
  "integration": "text",
  "url": "text",
  "updatedAt": "2025-04-12T21:04:01.285Z"
}

Was this helpful?