---
title: "Keep the site in sync with a repository branch: every version becomes a commit, pushes come back as versions"
method: PUT
path: "/builder/sessions/{sessionId}/github"
tags: ["Builder"]
---

# Keep the site in sync with a repository branch: every version becomes a commit, pushes come back as versions

`PUT /builder/sessions/{sessionId}/github`

## Request

- Base URL: `https://hostingsurge.com/api/v1`
- URL: `https://hostingsurge.com/api/v1/builder/sessions/{sessionId}/github`
- Auth: one of:
  - HTTP bearer
  - API key in cookie `__Host-hs_session`

## Path parameters

- `sessionId` string, uuid, required

## Request body

- object
  - `installationId` string, required
  - `repoFullName` string, required
  - `branch` string: Default: the repository's default branch
  - `start` 'push' | 'pull': A repository that already has code: push = the builder's site replaces its files (in a new commit), pull = the builder takes the repository's code. Required then (409 conflict, reason repository_not_empty)

## Response `200`

Connected

- object
  - `state` 'not_connected' | 'pending' | 'synced' | 'ahead' | 'behind' | 'diverged' | 'error', required
  - `available` boolean, required: Whether this server can reach customers' repositories (the GitHub App's key is configured)
  - `installationId` string, nullable, required
  - `accountLogin` string, nullable, required
  - `repoFullName` string, nullable, required
  - `repoUrl` string, nullable, required
  - `branch` string, nullable, required
  - `syncBranch` 'hostingsurge-sync', required
  - `pullRequestUrl` string, nullable, required: diverged: where to open the pull request from hostingsurge-sync
  - `lastSyncedAt` string, nullable, required: ISO-8601 timestamp
  - `error` object, nullable, required
    - `code` string, required
    - `message` string, required

## Other responses

- `400`: Invalid request (code invalid_request); an import that fails its check answers 200 with the check and no session
- `401`: Missing or invalid session/token (code unauthorized)
- `402`: GitHub sync needs a paid plan (code upgrade_required, details.feature builder.github_export)
- `403`: Not permitted, or the GitHub App has no access to write (code forbidden, details.reason not_permitted)
- `404`: Not found, or the GitHub account is not connected to the team (code not_found)
- `409`: The repository already has code: say whether the site replaces it or the builder takes it (details.reason repository_not_empty)
- `501`: GitHub sync is not switched on for this server (code not_configured)

---

[API](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api.md) · [All operations](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api/llms.txt) · [OpenAPI document](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api/revisions/4d08337cdff1?raw)
