Skip to main content
The Branch Protection API allows you to programmatically manage protection rules for repository branches.

Overview

Branch protection rules control:
  • Who can push to branches
  • Whether pull requests are required
  • Required reviews and status checks
  • Force push and deletion permissions

tRPC Endpoints

List Rules

Get all branch protection rules for a repository.
Response:

Get Rule

Get a specific branch protection rule.

Create Rule

Create a new branch protection rule.

Update Rule

Update an existing branch protection rule.

Delete Rule

Delete a branch protection rule.

Check Access

Check if an operation is allowed on a branch.

Get Branch Status

Get protection status for a specific branch.

Rule Schema

BranchProtectionRule

Violation Types

Presets

Apply common configurations using presets:

Preset Configurations

Basic:
Standard:
Strict:

Pattern Matching

Patterns support glob-style matching:

Library Usage

For direct library integration:

Error Handling