> ## Documentation Index
> Fetch the complete documentation index at: https://docs.entire.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Branch Rules

> Protect branches hosted on Entire from force pushes, direct pushes, and deletion.

Branch rules control how existing branches in repositories hosted on Entire can be updated or deleted. Each rule applies to a branch name or pattern and has one protection level. You need permission to manage repository settings to view or change the rules.

GitHub mirror rules are managed in the upstream GitHub repository. Entire also blocks direct pushes to the mirror's existing default branch.

## Protection Levels

| In repository settings | In the CLI | What the rule allows |
| - | - | - |
| **Block force pushes** | `protected` | Allows fast-forward pushes. Blocks changes that rewrite branch history and blocks deletion. |
| **Block direct pushes** | `server-side merge only` | Allows updates through merges performed by Entire, such as Trail merges. Blocks direct pushes even when they are fast-forward, and blocks deletion. |

You can **Block direct pushes** with [Gates](https://docs.entire.com/guides/trails/gates.md) to require approvals or checks before merging a Trail. Push your work to a branch that allows direct pushes, then merge it through a Trail that targets the protected branch.

## Branch Names and Patterns

* Use a branch name such as `main` to protect that specific branch.
* Use `HEAD` to protect whichever branch is currently the repository's default. The rule follows changes to the default branch.
* Use `*` to match zero or more characters or `?` to match one character. For example, `release/*` matches both `release/1.2` and `release/1.2/hotfix` because `*` can match `/`.

You can create a branch that matches a rule. The rule applies to subsequent updates and deletion. If a branch matches both protection levels, **Block direct pushes** takes precedence. Each repository can have up to 64 rules.

## Manage Branch Rules

> [tab] Entire.com
>
> 1. Open your repository and go to **Settings** then **Branch rules**.
> 2. Select **Add rule**.
> 3. Enter a **Branch name or pattern** and choose a **Protection level**.
> 4. Select **Add rule** to save.
>
> [Manage branch rules on Entire.com](https://customer-0x5hsk8lh27fm00g.cloudflarestream.com/b4c2842fdd66a2dc7cb855fe91c87220/iframe)
>
> To change a rule's protection level, open its actions menu, select **Edit rule**, and select **Save changes** after choosing the new level. To remove a rule, select **Remove rule** from its actions menu and confirm. To replace a pattern, add the new rule before you remove the old one.

> [tab] CLI
>
> Pass the repository path, such as `/et/acme/widget`, or its repository ID (ULID). If you use a bare repository name, pass its project name or ID with `--project`.
>
> ```bash theme={null}
> # List rules
> entire repo protection list /et/acme/widget
>
> # Allow fast-forward pushes to release branches and block force pushes and deletion
> entire repo protection add /et/acme/widget 'release/*'
>
> # Require Entire merges into the default branch
> entire repo protection add /et/acme/widget HEAD --server-side-merge-only
>
> # Switch the default branch rule to Block force pushes
> entire repo protection add /et/acme/widget HEAD --server-side-merge-only=false
>
> # Remove the release branch rule by its pattern
> entire repo protection remove /et/acme/widget 'release/*'
> ```
>
> Quote wildcard patterns so your shell passes them to the CLI. When you omit `--server-side-merge-only`, a new rule defaults to `protected` and an existing rule keeps its current level. Add `--json` to any of these commands for JSON output.
