@shinyaz

GitHub Branch Rulesets can protect main from force push and deletion without requiring PRs

1 min read

GitHub started showing a "Your main branch isn't protected" warning in repository settings. The old Branch Protection Rules still work, but Rulesets are now the recommended approach.

For personal repos where code changes go through PRs but content/ gets pushed directly to main, requiring PRs would block the content workflow. Rulesets let you pick only the rules you need.

Go to Settings → Rules → Rulesets → New branch ruleset and configure:

Ruleset name:       Protect main
Enforcement status: Active
Target branches:    Include default branch
Block force pushes: ON
Restrict deletions: ON

Leave everything else (Require PR, Require status checks, etc.) OFF. This prevents accidents like git push --force or git branch -d main while allowing normal pushes.

Unlike the older Branch Protection Rules, Rulesets can combine multiple rules and apply across an entire Organization. For personal repos, starting with just force push protection + deletion protection is the easiest first step.

Share this post

Shinya Tahara

Shinya Tahara

Solutions Architect @ AWS

I'm a Solutions Architect at AWS, providing technical guidance primarily to financial industry customers. I share learnings about cloud architecture and AI/ML on this site.The views and opinions expressed on this site are my own and do not represent the official positions of my employer.