---
title: Gitea/Forgejo Backend
description: Configure Gitea and Forgejo backends in Sveltia CMS for self-hosted Git repositories.
sidebar:
  label: Gitea/Forgejo
---

Gitea and its fork Forgejo are lightweight, self-hosted Git services that are easy to set up and use. Sveltia CMS offers comprehensive support for Gitea/Forgejo repositories, enabling efficient content management.

## Requirements

- Gitea 1.24 or later, or Forgejo 12.0 or later.
- A Gitea or Forgejo account.
- A Gitea or Forgejo repository to store the content.
- Write access to the repository. Users with read-only access can’t sign in, unless [Open Authoring](/docs/workflows/open) is enabled, which lets them contribute from a fork.
- Sveltia CMS installed in your project.

If the configured branch is [protected](https://docs.gitea.com/usage/access-control/protected-branches) and doesn’t allow a user to push:

- Collections using the [Simple Workflow](/docs/workflows/simple) and the [Asset Library](/docs/ui/asset-library) are read-only for that user, because they commit to the branch directly.
- Collections using the [Editorial Workflow](/docs/workflows/editorial) still work, because they commit to branches of their own. However, the Publish button is only shown to users who are allowed to merge into the branch.

:::warning[Breaking change from Netlify/Decap CMS]

Sveltia CMS requires newer versions of Gitea/Forgejo than Netlify/Decap CMS did to leverage enhanced, high-performance API capabilities. For security reasons, it’s recommended to use the latest stable versions of Gitea/Forgejo.

:::

### CSP

If your site uses a Content Security Policy (CSP), you may need to update it to allow requests to Gitea or Forgejo. See the [CSP documentation](/docs/security#setting-up-content-security-policy) for more details.

### CORS

In your Gitea or Forgejo instance, you may need to enable Cross-Origin Resource Sharing (CORS) to allow the Sveltia CMS admin interface to communicate with the backend API. Refer to the [Gitea](https://docs.gitea.com/administration/config-cheat-sheet#cors-cors) or [Forgejo](https://forgejo.org/docs/latest/admin/config-cheat-sheet/#cors-cors) documentation for instructions on how to configure CORS.

## Configuration

The base configuration for the Gitea/Forgejo backend is straightforward. You need to specify the `name` of the backend as `gitea` (or [`forgejo`](#forgejo-backend-name)) and provide the `repo` option with the format `owner/repo`, where `owner` is your Gitea/Forgejo username or organization name, and `repo` is the repository name.

```yaml YAML
backend:
  name: gitea
  repo: user/repo
```

```toml TOML
[backend]
name = "gitea"
repo = "user/repo"
```

```json JSON
{
  "backend": {
    "name": "gitea",
    "repo": "user/repo"
  }
}
```

```js JavaScript
{
  backend: {
    name: "gitea",
    repo: "user/repo",
  },
}
```

### Instance URL

By default, Sveltia CMS uses the public Gitea instance at `https://gitea.com`. If you use a self-hosted Gitea or Forgejo instance or a hosting service like [Codeberg](https://codeberg.org/), you need to set the `base_url` and `api_root` options in your backend configuration to point to your server URL.

```yaml YAML {4-5}
backend:
  name: gitea
  repo: owner/repo
  base_url: https://gitea.example.com
  api_root: https://gitea.example.com/api/v1
```

```toml TOML {4-5}
[backend]
name = "gitea"
repo = "owner/repo"
base_url = "https://gitea.example.com"
api_root = "https://gitea.example.com/api/v1"
```

```json JSON {5-6}
{
  "backend": {
    "name": "gitea",
    "repo": "owner/repo",
    "base_url": "https://gitea.example.com",
    "api_root": "https://gitea.example.com/api/v1"
  }
}
```

```js JavaScript {5-6}
{
  backend: {
    name: "gitea",
    repo: "owner/repo",
    base_url: "https://gitea.example.com",
    api_root: "https://gitea.example.com/api/v1",
  },
}
```

For Codeberg, use the following settings:

```yaml YAML {4-5}
backend:
  name: gitea
  repo: owner/repo
  base_url: https://codeberg.org
  api_root: https://codeberg.org/api/v1
```

```toml TOML {4-5}
[backend]
name = "gitea"
repo = "owner/repo"
base_url = "https://codeberg.org"
api_root = "https://codeberg.org/api/v1"
```

```json JSON {5-6}
{
  "backend": {
    "name": "gitea",
    "repo": "owner/repo",
    "base_url": "https://codeberg.org",
    "api_root": "https://codeberg.org/api/v1"
  }
}
```

```js JavaScript {5-6}
{
  backend: {
    name: "gitea",
    repo: "owner/repo",
    base_url: "https://codeberg.org",
    api_root: "https://codeberg.org/api/v1",
  },
}
```

The API version for Gitea/Forgejo is `v1`, so make sure to include `/api/v1` in the `api_root` option.

The `base_url` option is the URL of your Gitea/Forgejo instance, including the subpath if it’s served under one. This is because OAuth sign-in on the Gitea/Forgejo backend always uses [PKCE authorization](#pkce-authorization) without an OAuth client. With the `gitea` backend name, the `base_url` is not inferred from `api_root`, so you have to set both options. The [`forgejo` backend name](#forgejo-backend-name) infers it instead.

The OAuth authorization URL is made of `base_url` and the `auth_endpoint` option, which defaults to `login/oauth/authorize`. You don’t need to set `auth_endpoint` unless your instance uses a different path. Note that it must be a path, not a full URL like the one shown in the Decap CMS documentation. See [OAuth Endpoint](/docs/backends#oauth-endpoint) for details.

:::warning[Breaking change from Netlify/Decap CMS]

In Netlify/Decap CMS, the default origin of the `base_url` and `api_root` backend options is set to `https://try.gitea.io` (test instance). In Sveltia CMS, we changed it to `https://gitea.com` (public free service). In most cases, anyway, you need to set these options explicitly to point to your own Gitea/Forgejo instance.

:::

### Forgejo Backend Name

Decap CMS 3.15 added a separate `forgejo` backend. Sveltia CMS accepts that name too, so a Decap CMS configuration for Forgejo or Codeberg works unchanged. It uses the same Gitea/Forgejo backend, with every feature on this page, but the instance URL options work differently:

- `api_root` is required, because there’s no default instance.
- `base_url` is optional. It defaults to `api_root` without the `/api/v1` path, e.g. `https://codeberg.org`, so you only need one URL.

```yaml YAML {2,4}
backend:
  name: forgejo
  repo: owner/repo
  api_root: https://codeberg.org/api/v1
```

```toml TOML {2,4}
[backend]
name = "forgejo"
repo = "owner/repo"
api_root = "https://codeberg.org/api/v1"
```

```json JSON {3,5}
{
  "backend": {
    "name": "forgejo",
    "repo": "owner/repo",
    "api_root": "https://codeberg.org/api/v1"
  }
}
```

```js JavaScript {3,5}
{
  backend: {
    name: "forgejo",
    repo: "owner/repo",
    api_root: "https://codeberg.org/api/v1",
  },
}
```

Unlike Decap CMS, which defaults the `branch` option to `main` with this backend name, Sveltia CMS uses the repository’s default branch when `branch` is omitted, the same as with the `gitea` name.

## Authentication

:::tip

If you plan to only [work with your local repository](/docs/workflows/local), you don’t need to set up authentication.

:::

### Access Token (Quick Start) [#access-token]

If you or a small team of developers are the only users of your CMS instance, you can use an access token for authentication. This method is straightforward and doesn’t require setting up an OAuth app or updating the CMS configuration.

Click the “Sign In with Token” button on the login screen. The prompt dialog provides a link to the token generation page on Gitea/Forgejo with the required scopes pre-selected. Generate a new token, copy it to the clipboard and paste it into the prompt dialog to sign in. The token will be stored in the browser’s local storage and used for subsequent API requests.

The scopes depend on your configuration:

- `read:repository`, `write:repository` and `read:user` are always requested.
- `read:issue` and `write:issue` are added when the [Editorial Workflow](/docs/workflows/editorial) is enabled. The workflow labels its pull requests, and labels live under the issue scope.

If you turn the workflow on after generating a token, generate a new one. Otherwise, saving an entry fails with a permission error.

You can [disable token authentication](/docs/backends#authentication-methods) if needed.

### PKCE Authorization (Recommended) [#pkce-authorization]

To use PKCE authorization with Sveltia CMS, you need to register a new OAuth app on Gitea/Forgejo and update your Sveltia CMS configuration file accordingly. Here’s how:

1. Follow the instructions in the [Gitea](https://docs.gitea.com/development/oauth2-provider) or [Forgejo](https://forgejo.org/docs/latest/user/oauth2-provider/) documentation to create a new OAuth application.
1. Set the **Redirect URI** to your CMS admin URL, e.g. `https://your-domain.com/admin/`.
1. Uncheck the **Confidential** option.
1. Copy the Client ID of your registered OAuth app.

Then, update your Sveltia CMS configuration file to include the `app_id` option with your Client ID:

```yaml YAML {4}
backend:
  name: gitea
  repo: owner/repo
  app_id: YOUR_CLIENT_ID
```

```toml TOML {4}
[backend]
name = "gitea"
repo = "owner/repo"
app_id = "YOUR_CLIENT_ID"
```

```json JSON {5}
{
  "backend": {
    "name": "gitea",
    "repo": "owner/repo",
    "app_id": "YOUR_CLIENT_ID"
  }
}
```

```js JavaScript {5}
{
  backend: {
    name: "gitea",
    repo: "owner/repo",
    app_id: "YOUR_CLIENT_ID",
  },
}
```

Users’ OAuth tokens will be automatically renewed as needed, so there’s no need to worry about token expiration.

## Features

### Git LFS

Git Large File Storage (LFS) is supported out of the box in the Gitea/Forgejo backend. Just make sure to enable LFS in your repository settings. For more information, refer to the official documentation for [Gitea](https://docs.gitea.com/administration/git-lfs-setup) or [Forgejo](https://forgejo.org/docs/latest/admin/setup/storage/).

### GraphQL

GraphQL support is not available for Gitea/Forgejo repositories. Sveltia CMS uses the REST API to interact with Gitea/Forgejo.

### Commit Signing

Commit signing is supported in Gitea/Forgejo repositories, but you may need to configure it on your server. Please refer to the [Gitea](https://docs.gitea.com/administration/signing) or [Forgejo](https://forgejo.org/docs/latest/admin/advanced/signing/) documentation for more details on setting up commit signing.

### Service Status Checking

Service status checking is not available for Gitea/Forgejo repositories. If you are experiencing issues connecting to your Gitea/Forgejo instance, please verify the server status manually.

## Workflows

All [content management workflows](/docs/workflows) are supported with the Gitea/Forgejo backend:

- [Local Development Workflow](/docs/workflows/local)
- [Simple Workflow](/docs/workflows/simple)
- [Preview Workflow](/docs/workflows/preview)
- [Editorial Workflow](/docs/workflows/editorial)
- [Open Authoring](/docs/workflows/open)

## Deployment

Both Gitea and Forgejo support CI/CD pipelines that can be used to automate the deployment of your site whenever content is updated through Sveltia CMS. You can set up workflows to build and deploy your static site generator (SSG) whenever changes are pushed to the repository.

- [Gitea Actions](https://docs.gitea.com/usage/actions/overview)
- [Forgejo Actions](https://forgejo.org/docs/latest/user/actions/reference/)

Entries can link to the [deploy preview](/docs/deployments/previews) built for their pull request, and report whether the build has finished, when the workflow posts the preview address as a commit status. See [Reporting a Preview from Gitea/Forgejo Actions](/docs/deployments/previews#gitea-forgejo-actions).
