Skip to main content

🔐 Branch Protection Rules

Follow these steps to protect important branches like main or production:


✅ Steps​

  1. Go to Your Repository

    • Navigate to your repository on GitHub.
  2. Open Settings

    • Click on the "Settings" tab (requires admin access).
  3. Select "Branches"

    • In the left sidebar, click "Branches" under the "Code and automation" section.
  4. Add a Branch Protection Rule

    • Click the "Add branch ruleset" button.
  5. Configure the Rule

    • Branch name pattern: Enter the branch name (e.g., main,develop, release/*).
    • Enable the desired options:
      • ✅ Restrict deletions
      • ✅ Require a pull request before merging
        • Required approvals: at least 1
        • Require approval of the most recent reviewable push
        • Require conversation resolution before merging
      • ✅ Require status checks to pass
        • Require branches to be up to date before merging
  6. Save Changes

    • Click "Create" or "Save changes" at the bottom.

SettingDescription
✅ Require pull request reviewsEnforces code review before merging
✅ Require status checksEnsures CI/CD checks pass before merging
✅ Require linear historyKeeps commit history clean (no merge commits)
✅ Include administratorsApplies rules to admins as well
✅ Block force pushesLimits who can push directly to the branch

Main branch ruleset example:
image image image

💡 Tips​

  • Use wildcards like release/* to apply rules to multiple branches.
  • Combine with GitHub Actions for automated checks and workflows.
  • Regularly review and update rules as your team grows.