---
title: Git deployments
subtitle: Connect a GitHub or other Git repository, and pushes to the production branch publish automatically while every pull request gets a preview deployment.
description: Connect a ButterIX site to a Git repository — repository URL, branch, and access token; configure a GitHub webhook (Payload URL, Secret, events); deployment rules for pushes and pull requests, signature verification, working with the visual editor, and disconnecting.
---

## Connect a repository

<Steps>
  <Step title="Prepare the repository">
    The repository needs a `docs.yml` (at the repo root, or in a `fern/` or `biti/` subdirectory; the CLI and platform look for `docs.yml` → `docs.yaml` → `fern/docs.yml` → `biti/docs.yml` → `docs.json` → `mint.json` in that order).
  </Step>
  <Step title="Fill in the dashboard">
    Open the site's "Settings → Git repository" and enter:

    - **Repository URL**: starts with `https://`, e.g. `https://github.com/acme/docs.git`.
    - **Branch**: the production branch, default `main`.
    - **Access token**: private repositories need a token with read access; to publish from the visual editor (pushing back to the repo) it also needs write access. Tokens are stored encrypted; leave the field empty later to keep the current one.

    Click "Connect repository". The platform pulls the repo and starts a production deployment right away.
  </Step>
  <Step title="Configure the webhook">
    After connecting, the settings page shows a **Payload URL** and **Secret**. In your GitHub repo, go to Settings → Webhooks → Add webhook:

    | Field | Value |
    |---|---|
    | Payload URL | The URL shown on the settings page, like `https://api.butterix.com/v1/webhooks/github/site_2m4k8p` |
    | Content type | `application/json` |
    | Secret | The Secret shown on the settings page |
    | Events | Select **Pushes** and **Pull requests** |
  </Step>
</Steps>

You can also connect via the API: [Connect Git repository](/api-reference/git/connect-git).

## What triggers a deployment

```mermaid
flowchart LR
  P[push] -->|production branch| A[Production deployment]
  P -->|other branches| I[Ignored]
  PR[pull_request] -->|opened / synchronize / reopened| B[Preview deployment of that branch]
  PING[ping] --> OK[Returns ok]
```

| GitHub event | Condition | Result |
|---|---|---|
| `push` | Pushed to the production branch set when connecting | Production deployment; the message is the first line of the commit message, and the commit SHA is recorded |
| `pull_request` | Action is `opened`, `synchronize`, or `reopened` | Preview deployment from the PR's source branch, with message `PR #number: title` |
| `ping` | Sent by GitHub when the webhook is added | Returns `{ "ok": true }` |
| Other | | Returns `{ "ignored": true }` |

Once a preview deployment finishes, open its own URL from the dashboard's deployment list. See [Previews and rollbacks](./previews-and-rollbacks.mdx).

## Security

- Every request must carry an `X-Hub-Signature-256` header. The platform computes HMAC-SHA256 with the site's Secret and compares in constant time, returning 401 on mismatch.
- The webhook URL uses the site id (not the slug), and only sites connected to Git accept requests.
- The platform only **reads** content from the repository and builds it in a separate worker thread; MDX never executes any code (see [Safe subset](../writing/safe-mdx.mdx)).

## Working with the visual editor

You can still use the visual editor after connecting Git:

- Edits happen on a draft branch and **can't modify the production branch directly**;
- "Publish" merges the draft into the production branch, **pushes to the remote repository**, and then triggers a production deployment (requires a token with write access);
- Team members can commit from their IDE or edit in the editor; both are merged through Git.

## Manual redeploys

The dashboard's "Redeploy" and "Create preview deployment" buttons rebuild from the latest commit in the repository. You can also call [Create deployment](/api-reference/deployments/create-deployment) with `{ "branch": "feature/x", "preview": true }` to build any branch.

## Disconnect

After "Disconnect", the site goes back to the ButterIX hosted repository; later pushes no longer trigger deployments, and webhook requests return 404.
