---
title: "Make code review enforceable on a self-hosted forge · CloudSat"
description: "Turn code review into a merge rule on Forgejo, Gitea, GitLab or OneDev with protected branches, approvals, CODEOWNERS and CI checks, and see when Gerrit fits."
url: https://cloudsat.io/learn/code-review-on-a-self-hosted-forge
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[DevOps](https://cloudsat.io/learn/topic/devops-and-automation)

# Make code review enforceable on a self-hosted forge

Turn code review into a merge rule on Forgejo, Gitea, GitLab or OneDev with protected branches, approvals, CODEOWNERS and CI checks, and see when Gerrit fits.

CloudSat team November 18, 2026 8 min read

A review policy written in a wiki holds until the first urgent fix on a Friday evening. A forge can hold it for you: it can refuse merges that skipped review, approvals that predate the last push, and builds that failed. Each self-hosted forge exposes these rules differently, and some editions keep the important ones in paid tiers. This guide maps the switches that make review real, then looks at Gerrit, which builds the whole workflow around review.

## The rules that make review real

| Rule | What it prevents |
| --- | --- |
| Protected branch with no direct pushes | Skipping the pull request entirely |
| Required approvals | Merging without a second person |
| Dismiss or ignore stale approvals | Approving the first version and merging the third |
| CODEOWNERS | The wrong person approving a sensitive area |
| Required status checks | Merging a red build |
| Signed commits | Commits pushed under someone else's name |

Start with the first two on your default branch, then add the rest as the team grows.

## Forgejo and Gitea

Both forges share most of their branch protection, configured per repository under **Settings > Branches** with a branch name pattern such as `main` or `release/**`. The options that matter for review, named as in Gitea's interface (Forgejo's wording is close):

- **Required approvals**, counted from people with write access, or only from an allowlist when **Restrict approvals to allowlisted users or teams** is on.
- **Dismiss stale approvals** removes approvals when new commits change the content; **Ignore stale approvals** keeps them visible but stops counting them.
- **Block merge on rejected reviews** holds the merge while an official reviewer requests changes, even with enough approvals.
- **Block merge on official review requests** holds it while a requested review is still open.
- **Block merge if pull request is outdated** forces a rebase or merge when the head branch is behind the base.
- **Enable Status Check** with status check patterns lists the CI checks that must pass; the form shows checks it has seen recently, so you can pick their exact names.
- **Require Signed Commits** rejects pushes that are unsigned or unverifiable.
- **Protected file patterns** stop direct changes to files such as CI configuration, even by people allowed to push.

Authors cannot approve their own pull requests, so one required approval really means a second person.

### CODEOWNERS

A `CODEOWNERS` file requests reviews automatically from the owners of the paths a pull request touches. Gitea looks for it at the repository root, in `docs/` or in `.gitea/`; Forgejo uses the root, `docs/` or `.forgejo/`. Each rule is a Go regular expression, not a glob, followed by users or `org/team` names:

```text
# Paths are Go regular expressions; a literal dot needs escaping
migrations/.*   @acme/db-team
deploy/.*       @alice @acme/ops
docs/.*         @acme/editors
```

Gitea can go one step further with **Require approval from code owners**, which needs at least one approving owner per matching rule. On Forgejo, pair the automatic review requests with **Block merge on official review requests**, so a pull request waits while a requested owner has not reviewed yet.

On CloudSat, [Forgejo](https://cloudsat.io/apps/deploy-forgejo), [Gitea](https://cloudsat.io/apps/deploy-gitea), [OneDev](https://cloudsat.io/apps/deploy-onedev) and [GitLab](https://cloudsat.io/apps/deploy-gitlab) are one-click apps, so you can try these rules on a scratch repository before you change the real one.

## GitLab: check your tier first

GitLab's free tier covers less of this list than it seems. Its documentation marks merge request approvals as available everywhere, but in the free tier anyone with at least the Developer role can approve and approvals are optional: they do not prevent merging. Required approvals and approval rules need Premium or Ultimate, and so do Code Owners and push rules such as rejecting unsigned commits.

What the free tier does enforce:

- **Protected branches**, where you choose who may push and who may merge.
- **Pipelines must succeed** and **All threads must be resolved**, the merge checks under **Settings > Merge requests**.

That makes a workable setup: nobody pushes to `main`, only Maintainers merge, the pipeline must pass and every discussion must be resolved. What it cannot guarantee is that someone other than the author looked at the change. If you need that rule enforced by the server rather than by habit, budget for a paid tier or choose a forge where required approvals are free.

A merge request pipeline makes lint and tests a condition of merging:

```yaml
# .gitlab-ci.yml
lint:
  image: python:3.13-slim
  rules:

    - if: $CI_PIPELINE_SOURCE == "merge_request_event"

  script:

    - pip install ruff
    - ruff check .
    - ruff format --check .

```

For the larger platform, see [GitLab hosting](https://cloudsat.io/gitlab-server-hosting): it needs noticeably more memory than the lighter forges.

## OneDev: reviewers and jobs in one rule

OneDev puts review and CI requirements in the same branch protection rule. A rule names required reviewers and the jobs that must succeed before a merge; a failed job that is not required does not block it. File-path rules can demand a reviewer from a group for specific paths, for example a core-team member for changes to data models, and OneDev suggests group members from the history of the changed files. Its documentation states that a required review cannot be bypassed by removing the reviewer. Code comments are not limited to pull requests either: a discussion started on a file or a commit stays attached to its source location.

## Gerrit: every commit is reviewed

Gerrit replaces pull requests with changes. Each commit is reviewed on its own, and a new version of it becomes a new patch set of the same change. A `Change-Id` footer, added by a commit hook, ties the versions together:

```bash
# Install the hook once per clone
curl -Lo .git/hooks/commit-msg https://review.example.com/tools/hooks/commit-msg
chmod u+x .git/hooks/commit-msg

# Send a change for review against main
git push origin HEAD:refs/for/main

# Address comments: amend the same commit and push again as a new patch set
git commit --amend
git push origin HEAD:refs/for/main
```

Votes are labels. `Code-Review` runs from -2 to +2: +2 means approved, +1 means "looks good, but someone else must approve", and -2 blocks submission until the reviewer changes the vote. By default, a change needs at least one +2 to be submitted. The `Verified` label is optional at site setup and is usually voted by CI, which turns "the build passed" into a formal requirement.

Gerrit fits projects that want each commit reviewed as a unit, review long series of dependent changes, or gate merges strictly on CI. The costs are real: every contributor learns `refs/for`, amending and patch sets; it is a Java server with its own interface; and it has no issue tracker, so it is paired with one and often mirrored to a forge. The current release line is 3.14.

## Let bots write the mechanical comments

Human attention is the scarce part of review. Spend it on design, naming, tests and risk, and hand formatting and lint to machines:

- Run formatters and linters in CI and make the job a required check, so style never comes up in review.
- Use a tool such as reviewdog to post linter findings as inline comments. Its reporters include Gitea pull request reviews, GitLab merge request discussions and Gerrit change reviews.
- Keep the CI configuration under protected file patterns or Code Owners, so nobody can weaken the checks in the same change that would fail them.

## A checklist for the human part

1. Does the change do what its description says, and nothing else?
2. Are there tests for the new behavior and for the error paths?
3. Do database migrations run both forward and back, or is the rollback written down?
4. Are secrets, credentials or personal data kept out of the diff and the logs?
5. Will the next person understand the names and the comments?
6. Is the change small enough to review in one sitting? If not, ask for it in parts.

Signed commits complete the picture. Git can sign with an SSH key you already use:

```bash
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true
```

Add the same public key to your forge account so it can verify the signatures; some forges also ask you to prove ownership of the key.

## FAQ

### Can authors approve their own changes?

Not on Gitea or Forgejo, where the interface refuses it. On GitLab's free tier approvals are optional anyway, so the author's merge is limited only by who may merge. In Gerrit it depends on how labels and submit requirements are configured, so test it with a throwaway change.

### How many approvals should we require?

One for most repositories, which already guarantees a second person. Add a code owner rule for risky paths such as migrations, deployment and authentication, rather than raising the count everywhere and slowing every change.

### Do approvals survive new commits?

Only if you let them. On Gitea and Forgejo, turn on **Dismiss stale approvals** or **Ignore stale approvals**. Otherwise a reviewer can approve one version while a different one gets merged.

### Is Gerrit worth it for a small team?

Usually not as a first forge. Start with Forgejo, Gitea or OneDev and their branch rules. Gerrit pays off when per-commit review and strict CI gating are worth retraining every contributor.

**Run it on CloudSat.** Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. [See plans](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in DevOps](https://cloudsat.io/learn/topic/devops-and-automation)

- [Scala or Java for a JVM backend: what still separates them](https://cloudsat.io/learn/scala-or-java-for-a-jvm-backend): DevOps Scala or Java for a JVM backend: what still separates them 6 min read
- [Learn Rust for server software: when the effort pays off](https://cloudsat.io/learn/learn-rust-for-server-software): DevOps Learn Rust for server software: when the effort pays off 7 min read
- [Self-hosted kanban boards: Planka, WeKan, Vikunja and more](https://cloudsat.io/learn/self-hosted-kanban-boards-compared): Self-hosting Self-hosted kanban boards: Planka, WeKan, Vikunja and more 6 min read
- [Move off GitHub without breaking builds, links or history](https://cloudsat.io/learn/move-repositories-off-github): DevOps Move off GitHub without breaking builds, links or history 6 min read
