This guide explains how to set up branch protection rules in GitHub to enforce the branch naming convention and permissions.
- Go to your repository on GitHub
- Click on "Settings" tab
- Click on "Branches" in the left sidebar
- Branch name pattern:
feature/* - Settings to enable:
- ✅ Restrict pushes that create matching branches
- ✅ Restrict pushes that create matching files
- Under "Restrict pushes that create matching branches":
- Select "Restrict to organization members"
- Branch name pattern:
release/* - Settings to enable:
- ✅ Restrict pushes that create matching branches
- ✅ Restrict pushes that create matching files
- Under "Restrict pushes that create matching branches":
- Select "Restrict to organization members"
- Branch name pattern:
chore/* - Settings to enable:
- ✅ Restrict pushes that create matching branches
- ✅ Restrict pushes that create matching files
- Under "Restrict pushes that create matching branches":
- Select "Restrict to organization members"
- Branch name pattern:
hotfix/* - Settings to enable:
- ✅ Restrict pushes that create matching branches
- ✅ Restrict pushes that create matching files
- Under "Restrict pushes that create matching branches":
- Select "Restrict to organization members"
- Branch name pattern:
main - Settings to enable:
- ✅ Require a pull request before merging
- ✅ Require status checks to pass before merging
- Add "Branch Name Validation" and "Branch Permission Check" as required checks
- ✅ Require branches to be up to date before merging
- ✅ Require conversation resolution before merging
- ✅ Restrict pushes that create matching files
If you have GitHub Enterprise, you can also use:
-
Repository Rules (newer feature):
- Go to Settings > Rules > Rulesets
- Create rulesets for different branch patterns
- More granular control over permissions
-
Organization-level Rules:
- Set organization-wide policies
- Apply rules across multiple repositories
After setting up the rules:
- Test with an organization member account - should be able to create
feature/test,release/test,chore/test, andhotfix/testbranches - Test with an external account - should be blocked from creating
feature/*,release/*,chore/*, andhotfix/*branches - Verify that the GitHub Actions workflows run correctly on PRs
- The GitHub Actions workflows provide immediate feedback to contributors
- Branch protection rules provide server-side enforcement
- External contributors will see clear error messages explaining which branch patterns they can use
- Organization members have full access to all branch patterns
If external contributors report issues:
- Check if they're using the correct branch prefixes (
fix/,docs/,community/) - Verify the GitHub Actions workflows are enabled
- Ensure branch protection rules are correctly configured
- Check organization membership settings are properly configured