> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/developers/gitbook-api/api-reference/spaces/git/push-space-content-to-a-connected-git-repository.md).

# Push space content to a connected Git repository

Triggers an export of the space's current content to the linked Git repository. This is an async operation — the export runs in the background after the request returns 204. Use getSpaceGitInfo to check the current git sync status. The space must already have a Git provider configured.

```json
{"openapi":"3.1.0","info":{"title":"GitBook API","version":"0.0.1-beta"},"tags":[{"name":"space-git","description":"Manage the linkage between your GitBook space and external Git repositories, enabling commits, merges, and pull requests directly tied to your documentation.\n"}],"servers":[{"url":"{host}/v1","variables":{"host":{"default":"https://api.gitbook.com"}}}],"security":[{"user":[]},{"integration":[]},{"integration-installation":[]},{"oauth":["space:write"]}],"components":{"securitySchemes":{"user":{"type":"http","scheme":"bearer"},"integration":{"type":"http","scheme":"bearer"},"integration-installation":{"type":"http","scheme":"bearer"},"oauth":{"type":"oauth2","flows":{"authorizationCode":{"authorizationUrl":"https://oauth.gitbook.com/authorize","tokenUrl":"https://oauth.gitbook.com/token","scopes":{"user:read":"Read your GitBook user profile.","organization:read":"Read organization settings and metadata.","organization:write":"Create and update organization settings.","organization:members:read":"Read organization members, invites and link invites.","organization:members:write":"Manage organization members, invites and link invites.","organization:ask":"Ask AI questions across an organization's content.","organization:search":"Search across an organization's content.","space:read":"Read spaces and their content.","space:write":"Create, update and delete spaces and their content, including imports.","space:permissions:read":"Read space permissions.","space:permissions:write":"Manage space permissions.","change-request:merge":"Merge change requests, publishing their changes to the space.","site:read":"Read sites and their settings.","site:write":"Create, update and delete sites, sections and their settings.","site:publish":"Publish and unpublish sites, controlling their public exposure.","site:permissions:read":"Read site permissions.","site:permissions:write":"Manage site permissions.","site:auth:read":"Read site authentication and security configuration.","site:auth:write":"Manage site authentication and security configuration.","site:insights:read":"Read site analytics and insights.","site:ask":"Ask AI questions across a site's content.","site:search":"Search across a site's content.","openapi:read":"Read OpenAPI specifications.","openapi:write":"Create, update and delete OpenAPI specifications."}}}}},"parameters":{"spaceId":{"name":"spaceId","in":"path","required":true,"description":"The unique id of the space","schema":{"$ref":"#/components/schemas/EntityId"}}},"schemas":{"EntityId":{"type":"string","pattern":"^[a-zA-Z0-9_-]+$","description":"A unique entity identifier"},"ExportToGitRepository":{"type":"object","properties":{"url":{"type":"string","description":"URL of the Git repository to export to. It can contain basic auth credentials."},"ref":{"type":"string","description":"Git ref to push the commit to in the format \"refs/heads/main\""},"commitMessage":{"type":"string","description":"Message for the commit generated by the export"},"repoCacheID":{"type":"string","description":"Unique identifier to use to cache the Git repository across multiple operations.","deprecated":true},"repoTreeURL":{"type":"string","description":"URL to use as a prefix for external file references."},"repoCommitURL":{"type":"string","description":"URL to use as a prefix for the commit URL."},"repoProjectDirectory":{"type":"string","description":"Path to a root directory for the project in the repository."},"timestamp":{"description":"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.\n","$ref":"#/components/schemas/Timestamp"},"force":{"type":"boolean"},"standalone":{"type":"boolean","description":"If true, the export will be done in a standalone mode, meaning that the exported content will not be linked to the Git repository. This is useful for creating a snapshot of the space's content.\n"},"gitInfo":{"description":"Optional metadata to store on the space about the Git provider","$ref":"#/components/schemas/UpdateSpaceGitInfo"}},"required":["url","ref","commitMessage"]},"Timestamp":{"type":"string","format":"date-time"},"UpdateSpaceGitInfo":{"type":"object","description":"Update metadata about the Git provider on the space","properties":{"provider":{"type":"string","description":"The git provider","enum":["github","gitlab"]},"url":{"type":"string","description":"The repository's tree URL"}}}}},"paths":{"/spaces/{spaceId}/git/export":{"post":{"operationId":"exportToGitRepository","summary":"Push space content to a connected Git repository","description":"Triggers an export of the space's current content to the linked Git repository. This is an async operation — the export runs in the background after the request returns 204. Use getSpaceGitInfo to check the current git sync status. The space must already have a Git provider configured.","tags":["space-git"],"parameters":[{"$ref":"#/components/parameters/spaceId"}],"responses":{"204":{"description":"Operation to export the space has been started."}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ExportToGitRepository"}}}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook.com/docs/developers/gitbook-api/api-reference/spaces/git/push-space-content-to-a-connected-git-repository.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
