# Git deploy

> Deploy a site from GitHub, GitLab, Gitea or your own Git server with a read-only deploy key and a webhook, or push straight to the server, with build actions, zero-downtime releases, rollback and a preview per branch.

Source: https://www.berthpanel.app/library/git-deploy/ · Category: apps · Updated: 2026-10-30

Git deploy rolls code from a repository out to a folder in the webspace: by hand with a button, automatically on every push through a webhook, or by pushing directly to the server. With releases on, each deploy goes into its own folder and the site switches over only when everything succeeded, so visitors never see a half-deployed site and you can go back with one click.

## Add a repository

On the domain page, open *Git* and click **Add repository**:

1. Enter the **URL** of the repository:
   - `https://…` for a public repository,
   - `git@github.com:acme/site.git` (SSH) for a private one; the panel then creates a deploy key,
   - or choose to **push to the server** yourself (see below).
2. Choose the **branch** (default `main`) and the **target folder** in the webspace. Empty means the domain's document root.
3. Optionally fill in **actions** that run after every deploy, in the target folder, such as `composer install --no-dev`.
4. Optionally pick a **preset** and switch on releases (below).

```bash
berth git add --domain example.com --name site --url git@github.com:acme/site.git \
  --branch main --target httpdocs --actions "composer install --no-dev" --auto
```

Files that are not in Git, such as uploads, stay where they are on every deploy.

### Deploy key for private repositories

For an SSH URL, the panel generates a key pair per repository and shows the public **deploy key**. Add it to the repository as a **read-only** key: in GitHub under *Settings → Deploy keys*, in GitLab under *Settings → Repository → Deploy keys*, in Gitea under *Settings → Deploy Keys*. The private key stays on the server and only gives read access to that one repository.

## Deploy on every push (webhook)

With *Deploy automatically* on, the panel shows a **webhook address** once. Note it down; the panel stores only a hash of its secret and cannot show it again. In GitHub, add it under *Settings → Webhooks → Add webhook* with content type `application/json`; GitLab and Gitea work the same way. Every push to the chosen branch is then deployed.

```bash
berth git hook --domain example.com --name site --on    # new address, shown once
berth git hook --domain example.com --name site --off   # the address stops working
```

Switching it off and on again gives a new address, which is also how you rotate the secret.

Without a webhook, deploy with **Deploy now** or:

```bash
berth git deploy --domain example.com --name site
```

## Push straight to the server

Instead of a remote repository, you can push to the panel over SSH, as you would to a Git host. Create the repository with `push` as its URL:

```bash
berth git add --domain example.com --name site --url push --releases
```

The *Git* page then shows the remote to add. Add it once, then push:

```bash
git remote add server <address shown in the panel>
git push server main
```

You authenticate with your own SSH key (domain page, *SFTP and SSH* → *SSH keys*), so the package needs SSH access. Every push is deployed within half a minute. See [Files, FTP and SSH](https://www.berthpanel.app/library/files-ftp-ssh/).

## Zero-downtime releases and rollback

With **releases** on, each deploy goes into its own folder `<target>/releases/<time>`, and a `current` link points at the active one. The document root is set to `<target>/current` (or `<target>/current/public`). A deploy that fails, including its actions, never becomes active.

- **Shared paths** stay across releases, for example `storage`, `.env` or `public/uploads`. They live once, outside the release folders, and each release links to them.
- **Kept releases**: the last few releases stay on disk (5 by default) so you can go back.
- **Rollback** switches `current` back to the previous release immediately.

```bash
berth git add --domain example.com --name app --url git@github.com:acme/app.git \
  --releases --keep 5 --shared storage --shared .env --doc-output public
berth git rollback --domain example.com --name app
```

`--doc-output` points the document root at a folder inside the code after the first successful deploy, for example `dist` or `public`.

## Presets

Presets fill in actions, releases, shared paths and the output folder for common setups:

| Preset | Actions | Site folder |
|---|---|---|
| `laravel` | `composer install --no-dev --optimize-autoloader --no-interaction && php artisan migrate --force && php artisan optimize`; `storage` and `.env` shared | `public/` |
| `npm-static` (Vite, Astro, Eleventy, …) | `npm ci && npm run build` | `dist/` |
| `nextjs-export` (Next.js static export) | `npm ci && npm run build` with `output: 'export'` | `out/` |
| `hugo` | `hugo --minify` (Hugo must be installed on the server) | `public/` |

```bash
berth git add --domain example.com --name site --url https://github.com/acme/site.git --preset npm-static --auto
```

For a Node.js server rather than static output, deploy the code with Git and run it as an [app](https://www.berthpanel.app/library/node-python-apps/).

## Preview per branch

Every branch other than the main branch can get its own environment at `<branch>.<preview base>`, for example `feature-login.preview.example.com`. The preview base must be a domain of the subscription or a name below it, with a wildcard DNS record pointing at the server. Each preview lives in its own folder in the webspace and is deployed on every new commit of its branch; when a branch disappears, its preview goes too.

```bash
berth git preview --domain example.com --name site --base preview.example.com
berth git preview --domain example.com --name site --base ""     # previews off; existing ones are removed
```

## Watch the outcome

The *Git* page shows per repository the branch, how it deploys (button, webhook or push), the commit that is live, the last deploy and its output. A failed deploy keeps the previous version online and shows why.

```bash
berth git list --domain example.com
berth git remove --domain example.com --name site   # repository and deploy key go; files stay
```

## Security notes

- Deploys and actions run as the subscription's system user, inside its resource limits, never as root.
- The deploy key is read-only and unique per repository; removing the repository removes the key.
- The webhook only triggers a fetch of the configured branch; it cannot pass code or commands.
- Secrets belong in the domain's environment (*Developers → Environment*) or in a shared `.env`, not in the repository; see [Node.js and Python apps](https://www.berthpanel.app/library/node-python-apps/#environment-variables-and-secrets).
