How to protect the main branch on GitHub and GitLab
Why it matters
An unprotected default branch accepts a force-push or a direct commit from anyone with write access — or anyone holding their token. Protection (or a ruleset) requires review and green CI first.
How to fix it
What to do: Enable branch protection for
main in GitHub settings.GitHub → Settings → Branches → Branch protection rules → Add rule
Branch name pattern: main
Enable:
✓ Require a pull request before merging
✓ Require approvals: 1
✓ Require status checks to pass before merging
✓ Require branches to be up to date before merging
✓ Require conversation resolution before merging
✓ Do not allow bypassing the above settings
Does your repository pass this check?
Free for public GitHub repositories, no account needed. 50+ DevOps and security checks in about ten seconds.