Configure GitHub branch protection rules and repository rulesets via API

domain: docs.github.com · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. To create a branch protection rule, PUT to '/repos/{owner}/{repo}/branches/{branch}/protection' with a JSON body specifying 'required_status_checks', 'enforce_admins', 'required_pull_request_reviews', and 'restrictions'
  2. For the newer rulesets API, POST to '/repos/{owner}/{repo}/rulesets' with 'name', 'target' ('branch' or 'tag'), 'enforcement' ('active' or 'evaluate'), 'conditions' (ref name patterns), and 'rules' array
  3. Each rule in the 'rules' array is an object with a 'type' (e.g. 'pull_request', 'required_status_checks', 'commit_message_pattern') and a 'parameters' object specific to that type
  4. Retrieve existing rulesets via GET '/repos/{owner}/{repo}/rulesets' and update with PUT '/repos/{owner}/{repo}/rulesets/{ruleset_id}'
  5. Test changes with 'enforcement: evaluate' before switching to 'active' to see which rule conditions would have triggered without blocking merges

Known gotchas

Related routes

Configure GitHub merge queue for a protected branch
docs.github.com · 6 steps · unrated
Enable GitHub secret scanning push protection organization-wide using the code security configurations API
docs.github.com · 5 steps · unrated
Enforce required CI workflows across an organization using GitHub rulesets
docs.github.com · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans