Skip to content
Try Gitea Cloud ☁️ for 30 days → Accelerate your Development & Deploys!
This is the documentation of the next version, still under development. See the latest release.

Protected branches

Protected branches prevent unwanted changes by enforcing push, deletion, and merge policies on selected branches. The rules are enforced for every Git protocol (HTTP(S), SSH), the web editor, the API, and background jobs such as auto-merge. Only repository owners and administrators can manage the rules, and the Branches page is read-only while a repository is archived.

  1. Open the repository and select Settings → Branches (repository admin permission required).
  2. Select Add new rule or Edit next to an existing rule.
  3. Fill in the Protected branch name pattern and optional file patterns, then configure the push, deletion, merge, and review options described below.
  4. Select Save rule.

The rule immediately applies to all matching branches, even if the branches are created in the future.

  • The Protected branch name pattern accepts glob expressions and matches the entire branch name. Patterns are case-sensitive. Using a simple name such as main without glob special characters always matches that specific branch (case-insensitive).
  • If multiple rules match the same branch, only the first rule is used. Reorder the list on the Branches page by dragging the grab handle. The first entry (priority 1) has the highest priority, so place patterns such as main or release/* before generic fallbacks such as *.

Example patterns:

Pattern Matches
main The main branch only
release/* release/v1.0, release/april
hotfix/** Nested branches such as hotfix/security/CVE
* Every branch (use as a fallback)
  • Protected file patterns block changes to sensitive files (for example .drone.yml or /docs/**/*.txt). Patterns are case-insensitive and separated by semicolons. Commits and merge attempts that touch one of the files are rejected.
  • Unprotected file patterns do the opposite: if pushes are blocked, users with write access can still push commits that modify only the listed files. This is useful for letting contributors update documentation while still requiring pull requests for code.

Both fields use the same glob syntax and match paths relative to the repository root.

The Push section controls direct pushes (including the web editor and API).

  • Disable push makes the branch read-only. Any attempt to push directly fails, and changes must be merged through pull requests.
  • Enable push allows anyone with write access to push (force pushes are still blocked unless explicitly allowed).
  • Allowlist restricted push requires being on the allowlist. Choose users and, for organization-owned repositories, teams.

The user allowlists for push, force-push and deletion can include the Gitea Actions and Deploy Key system users. They still require write access; Deploy Key also covers deploy tokens.

When a push is blocked, the server-side hook rejects the update with an explanation.

Force pushes have their own set of options:

  • Disable force push completely forbids rewriting history on the branch.
  • Enable force push allows anyone who can push to also force push.
  • Allowlist restricted force push limits force pushes to a separate allowlist of users or teams and requires regular push access.

The Branch Deletion section controls whether matching protected branches can be deleted:

  • Disable branch deletion prevents deletion. This is the default.
  • Enable branch deletion allows anyone who can push to delete the branch.
  • Allowlist restricted branch deletion limits deletion to a separate allowlist of users or teams and requires regular push access.

These rules apply to Git (git push --delete), the API, the web interface and post-merge cleanup. The default branch and configured default pull request target branch cannot be deleted.

  • Merge allowlist: keep the default to let anyone with write access merge pull requests, or enable the allowlist to restrict merges to selected users/teams.
  • Required approvals: specify how many approvals are needed before a merge is allowed. Reviews from users with write access count, unless the Restrict approvals to allowlisted users or teams option is enabled.
  • Dismiss stale approvals removes existing approvals whenever new commits that change the pull request content are pushed.
  • Ignore stale approvals keeps approvals but does not count reviews that were made on older commits. This option is disabled while dismissal of stale approvals is enabled.
  • Block merge on rejected reviews prevents merging while any official reviewer has requested changes.
  • Block merge on official review requests blocks merges while there are outstanding review requests (for example when CODEOWNERS requires a review).
  • Block merge if the pull request is outdated makes sure the head branch is up to date with the base branch before it can be merged.
  • Administrators must follow branch protection rules removes the ability for repository administrators to bypass the rules with the “Force merge” button.

Protected file patterns apply to pull requests as well. When a pull request changes one of the protected files, the pull request banner shows the affected paths and merging stays disabled.

Enable status checks to require one or more CI jobs to succeed before merging:

  1. Check Enable status check.
  2. Enter one pattern per line in Status check patterns. Each pattern is a glob expression that matches the context name reported by Actions, Drone, Woodpecker, or another Check API client (for example actions/test-*).
  3. Pick contexts from the table of jobs that have reported results in the last week to verify their names.

When the option is active, Gitea requires at least one context that matches each pattern to report success on the pull request head commit. An empty list is not allowed; use * to require the latest commit to be successful regardless of the context name.

Require merge queue sends every merge into matching branches through a queue, which tests each pull request together with the ones ahead of it before merging.

  • Merge when ready adds the pull request to the queue, right away or once all requirements are met.
  • The queue tests it on a gitea-merge-queue/<base>/pr-<number>-<sha> branch and merges it when the required checks pass. Pull requests that fail, time out or conflict are removed.
  • Queued pull requests can’t be updated or retargeted.
  • Only users who can bypass branch protection can push to the branch directly or merge with Merge without waiting for requirements to be met (bypass rules).

The queue page at /{owner}/{repo}/queue/{branch} lists the queued pull requests, and lets administrators move one to the front or clear the queue.

Run the required checks on merge_group. A required Gitea Actions check like ci / test (pull_request) is satisfied in the queue by the same job’s merge_group run:

on:
pull_request:
merge_group:

Exclude gitea-merge-queue/** from push workflows to avoid duplicate runs. The prefix can be changed with MERGE_QUEUE_BRANCH_PREFIX.

The queue settings:

  • Merge method for all queued pull requests.
  • Build concurrency limits how many pull requests are tested at once, 0 pauses the queue.
  • Minimum group size and Maximum group size set how many pull requests merge together. The queue waits up to Wait time to meet minimum group size for enough of them.
  • Require all queue entries to pass required checks: when disabled, only the last commit of a group must pass.
  • Status check timeout counts checks without a result after this time as failed.
  • Require signed commits rejects pushes that contain unsigned or unverifiable commits. The check runs inside the server hook before the push is accepted.
  • Protected file patterns (see above) prevent both pushes and merges that modify sensitive files.
  • Unprotected file patterns allow limited pushes while keeping the branch protected.