# Branch and tag protection

Only people with write access can push to your repository. These rules stop a mistake, a rushed push or someone with a leaked token from changing what users install.

Source: https://ha-barkley.github.io/security/controls/branches-and-tags/

From HASC, the Home Assistant Security Controls for integrations, cards and apps. A community catalog, not an official Home Assistant or Open Home Foundation project.

Each control has an ID, cited as HASC-CI-4, and a level from 1 to 3. "Level marker" means anyone can check the control from outside the project, and levels are graded on those controls only.

> **From the 2026 sweep.** Of the 909 apps that run a security check, 537 protect their main branch, and across the whole Marketplace, 85 apps released a tag whose commit isn't on main at all. The [Marketplace report](https://ha-barkley.github.io/marketplace/2026/security-basics/) has more on this.

## Why this matters

Your checks only protect users if code can't reach them any other way. Branch rules make main that place. Nothing lands there without passing the checks, and nobody can rewrite what's already there.

That only helps if your releases come from main too. A tag can point at any commit, including one on a side branch that never ran your checks, and a release built from it skips all of them. Tag rules then keep a published version from being moved to different code later.

## Controls

### BR-1: Add a branch ruleset for main

*Level 2 · Level marker*

Settings → Rules → Rulesets → New branch ruleset.

- Enforcement: *Active*.
- Target: the default branch.
- Turn on *Restrict deletions*.
- Turn on *Block force pushes*.
- Turn on *Require a pull request before merging*. Zero required approvals is fine if you work alone, because the pull request still runs your checks before anything lands.

### BR-2: Require your checks to pass

*Withdrawn*

Withdrawn on November 27, 2026, because [GATE-1](https://ha-barkley.github.io/security/controls/blocking-checks/#gate-1) and [GATE-2](https://ha-barkley.github.io/security/controls/blocking-checks/#gate-2) require the same checks and name them.

### BR-3: Keep the bypass list short

*Level 2*

If you add yourself so you can merge in an emergency, every bypass is logged. Don't add bots or apps you don't control.

### BR-4: Add a tag ruleset for your release tags

*Level 3 (or immutable releases) · Level marker*

Settings → Rules → Rulesets → New tag ruleset.

- Enforcement: *Active*. A disabled ruleset protects nothing.
- Target: `v*`, or however you name versions.
- Turn on *Restrict updates* and *Restrict deletions*, so a published version can't be moved to different code later.
- Turn on *Restrict creations* if only you should cut releases. Then add the Repository admin role to the bypass list, or you won't be able to push new tags either.

### Check it worked

In a test clone, change the last commit with `git commit --amend` and try `git push --force` to main. GitHub should refuse it. Then move an old tag with `git tag -f v1.0.0 HEAD` and `git push --force origin v1.0.0`, which GitHub should refuse too. `git fetch --tags --force` puts your local tag back. If you're on the bypass list, both pushes go through.

Barkley flags a release tag whose commit isn't on the main branch.
