Setting Up Branch Protection
Welcome to Ship Guard! 🎉 This guide will help you set up branch protection in under 5 minutes.
Why Branch Protection Matters
Without branch protection:
- ❌ Developers can still merge PRs even when Ship Guard reports errors
- ❌ Your team's coding standards won't be enforced
- ❌ The automated review becomes just a suggestion
With branch protection:
- ✅ PRs with Ship Guard errors are blocked from merging
- ✅ Your coding standards are automatically enforced
- ✅ Only clean, compliant code reaches your main branch
How to Set Up Branch Protection
-
Navigate to Repository Settings
- Go to your repository on GitHub
- Click on "Settings" tab (you need admin/owner permissions)
-
Access Branch Protection Rules
- In the left sidebar, click "Branches"
- Click "Add rule" or "Add branch protection rule"
-
Configure the Rule
- Branch name pattern: Enter
main(ormasterif that's your default branch) - Require status checks to pass before merging: ✅ Check this box
- Require branches to be up to date before merging: ✅ Check this box
- Branch name pattern: Enter
-
Add Ship Guard as Required Check
- In the "Status checks" section, search for "Ship Guard"
- ✅ Check the box next to "Ship Guard"
- This ensures PRs cannot be merged if Ship Guard reports any errors
-
Additional Recommended Settings
✅ Require a pull request before merging
✅ Require approvals (set to 1 or more as needed)
✅ Dismiss stale PR approvals when new commits are pushed
✅ Require review from code owners (if you have a CODEOWNERS file) -
Save the Rule
- Click "Create" or "Save changes"
Visual Guide
Here's what the branch protection settings should look like:
┌─────────────────────────────────────────────┐
│ Branch protection rule │
├─────────────────────────────────────────────┤
│ Branch name pattern: main │
│ │
│ ✅ Require a pull request before merging │
│ ✅ Require status checks to pass before │
│ merging │
│ └─ ✅ Ship Guard │
│ ✅ Require branches to be up to date before │
│ merging │
│ ✅ Require approvals: 1 │
└─────────────────────────────────────────────┘
Testing Branch Protection
After setting up branch protection, test it:
- Create a PR with code that triggers a Ship Guard error
- Try to merge the PR
- You should see: "Merging is blocked - Ship Guard has not passed"
Important Notes
- Admin permissions required: Only repository admins/owners can set up branch protection
- Organization settings: If this is an organization repository, you might need organization admin permissions
- Existing PRs: Branch protection only affects new PRs; existing PRs may need to be updated
- Bypass permissions: Consider who can bypass branch protection (usually only admins)