# branch-protection

Protect main: require PRs + 1 review + status checks, block force-push and deletion via the REST API; what to do when the free plan returns 403 on private repos (CODEOWNERS, rulesets on paid plans).

- **Space:** github-ops-public (https://github.com/Tech-Realm/space-github-ops-public/tree/main/branch-protection)
- **Level:** L1 (as the registry reports it)
- **Keys it needs (names only):** GITHUB_TOKEN
- **Tools:** gh
- **Routes:** gh-cli; checks: 2
- **Uses:** new (no recorded use yet)
- **Install:** `logicpacks pack use github-ops-public/branch-protection` or MCP `get_pack github-ops-public/branch-protection`
- **Files:** CHANGELOG.md, code/protect.sh, outcome/EVIDENCE.md, outcome/checks.yaml, outcome/results.json, pack.yaml, spec/SPEC.md, spec/source.md

## Purpose (spec/SPEC.md)

Protect main: require PRs + 1 review + status checks, block force-push and deletion via the REST API; what to do when the free plan returns 403 on private repos (CODEOWNERS, rulesets on paid plans).

## Goal

Nobody (agents included) can push straight to main or force-push over history.

## Steps

1. Read current state (read-only): `gh api repos/<o>/<r>/branches/main/protection` (404 = unprotected, 403 = plan doesn't allow).
2. Apply: `bash code/protect.sh <o> <r> main` (PR required, 1 approval, dismiss stale reviews, no force-push/deletion, linear history).
3. Add `.github/CODEOWNERS` so the owner is requested on every PR.
4. On 403 (free plan + private repo): decide upgrade vs trust + CODEOWNERS; record the decision.

## Edge cases

- Admins can bypass unless enforce_admins is true; agents often run as admin.
- Required status checks must match job names exactly.

## Don'ts




---

Canonical URL: https://logicpacks.io/packs/github-ops-public/branch-protection

Developed by TechRealm (techrealm.online), the software team. Operated by Al Jash Trading (Establishment), Abu Dhabi, since 1994, the legal entity that hosts and is responsible for the service. Economic licence CN-1030597, Abu Dhabi Registration Authority. Address: Office 5, Bani Yas West 4, Bani Yas, Abu Dhabi, UAE. Website: https://aljashtrading.com. Contact: hello@logicpacks.io, security@logicpacks.io, WhatsApp +1 713 632 2262 (https://wa.me/17136322262).

Machine-readable index: [/llms.txt](/llms.txt). Plain facts: [/about.md](/about.md). Safety: [/safety.md](/safety.md).
