Ready-to-use GitHub branch protection rulesets that can be imported directly into your repository.
Use for: Personal projects, learning repos, experiments
Features:
- Blocks force pushes to main
- Blocks branch deletion
- Requires pull requests (but allows self-merge)
- No review requirements
Best for: Solo developers who want basic safety without bureaucracy.
Use for: Most open source projects
Features:
- Blocks force pushes and deletions
- Requires linear history (squash/rebase merging)
- Requires 1 approval on pull requests
- Dismisses stale reviews on new commits
- Requires CI and test checks to pass
- Requires branches to be up to date before merging
- Admins can bypass with pull request
Best for: Active open source libraries, tools, and applications.
Use for: Security-critical or production infrastructure projects
Features:
- All Standard Protection features
- Applies to both
mainandrelease/*branches - Requires 2 approvals on pull requests
- Requires signed commits (GPG/SSH)
- Requires code owner approval
- Requires last push approval (no self-merge)
- Additional required checks: security-scan, code-coverage
- No bypass actors (even admins follow rules)
Best for: Security tools, financial applications, infrastructure projects.
- Go to your repository Settings → Rules → Rulesets
- Click New ruleset → Import a ruleset
- Upload one of the JSON files from this directory
- Review settings
- Click Create
# Install GitHub CLI if needed
brew install gh
# Authenticate
gh auth login
# Import ruleset
gh api repos/{owner}/{repo}/rulesets \
--method POST \
--input rulesets/standard-protection.json# Using curl
curl -X POST \
-H "Authorization: token YOUR_TOKEN" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/OWNER/REPO/rulesets \
-d @standard-protection.jsonAfter importing, you can customize:
Edit the required_status_checks array to match your CI workflow:
{
"type": "required_status_checks",
"parameters": {
"required_status_checks": [
{
"context": "build",
"integration_id": null
},
{
"context": "lint",
"integration_id": null
},
{
"context": "test",
"integration_id": null
}
]
}
}Status check names must match your GitHub Actions workflow job names.
Apply to different branches:
{
"conditions": {
"ref_name": {
"include": [
"refs/heads/main",
"refs/heads/develop",
"refs/heads/release/*"
],
"exclude": [
"refs/heads/experimental/*"
]
}
}
}Allow specific roles, teams, or apps to bypass rules:
{
"bypass_actors": [
{
"actor_id": 5,
"actor_type": "RepositoryRole",
"bypass_mode": "pull_request"
},
{
"actor_id": 1234,
"actor_type": "Team",
"bypass_mode": "always"
}
]
}Actor types:
RepositoryRole: 5 (Admin), 4 (Maintain), 2 (Write)Team: GitHub team IDIntegration: GitHub App ID (e.g., Dependabot)
Bypass modes:
always: Can completely bypass rulespull_request: Must use PR but can self-approve
To find the exact names of your status checks:
- Go to a recent pull request
- Scroll to the checks section
- Note the exact names (case-sensitive)
Or check your workflow file:
# .github/workflows/ci.yml
name: CI # This is the workflow name
jobs:
test: # This is the job name (the status check name)
runs-on: ubuntu-latest
steps:
- run: make testStatus check name will be: test
Before enabling status check requirements, ensure your workflows run on pull requests:
# .github/workflows/ci.yml
name: CI
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tests
run: make testSolution: Run the workflow at least once on a pull request to register the check name.
Solution: Add admin role to bypass_actors or temporarily disable the ruleset.
Solution: Add Dependabot as bypass actor:
{
"actor_id": 29,
"actor_type": "Integration",
"bypass_mode": "pull_request"
}Or use auto-merge workflow (see docs/branch-protection.md).
Test on a non-critical branch first:
- Create test branch:
git checkout -b test-protection - Import ruleset but apply only to
test-protectionbranch - Test PR workflow
- Verify all checks work
- Update ruleset to apply to
main
- Start with minimal ruleset
- Add team workflows for CI/tests
- After 1-2 weeks, upgrade to standard
- Monitor for issues
- Adjust as needed
- Export existing rules (if possible)
- Review with team
- Import new ruleset on test branch
- Test thoroughly
- Replace legacy rules with new ruleset
- Branch Protection Guide - Comprehensive documentation
- GitHub Rulesets Documentation
- CODEOWNERS Syntax
Need help? Open an issue or see our Support Guide.