Branch Protection Rules Setup Guide
π Setting Up Branch Protection
Follow these steps to configure branch protection rules for safe deployments.
Step 1: Navigate to Branch Protection Settings
- Go to your repository: https://github.com/LarryAnglin/HelpDesk
- Click Settings tab
- Click Branches in the left sidebar
- Click Add rule button
Step 2: Protect the main Branch (Production)
Create a new rule with these settings:
Branch name pattern: main
β Require a pull request before merging
- β
Require approvals:
1 - β Dismiss stale pull request approvals when new commits are pushed
- β Require review from CODEOWNERS (if you have a CODEOWNERS file)
β Require status checks to pass before merging
- β Require branches to be up to date before merging
- Required status checks:
build-and-deploy(from your GitHub Actions)
β Require conversation resolution before merging
β Include administrators
- This ensures even you follow the rules
β οΈ Do not allow bypassing the above settings
Click Create to save.
Step 3: Protect the develop Branch (Staging)
Click Add rule again and create a rule for develop:
Branch name pattern: develop
β Require a pull request before merging
- β
Require approvals:
1(or0for faster development) - β Dismiss stale pull request approvals when new commits are pushed
β Require status checks to pass before merging
- Required status checks:
build-and-deploy
β Require conversation resolution before merging
β Include administrators (optional - allows you to push directly for hotfixes)
Click Create to save.
Step 4: Create the develop Branch
Run these commands locally:
# Create and push develop branchgit checkout maingit pull origin maingit checkout -b developgit push -u origin developStep 5: Set Default Branch (Optional)
To make PRs target develop by default:
- Go to Settings β General
- Under βDefault branchβ, click the switch icon
- Select
develop - Click Update
π Recommended Workflow After Setup
For New Features:
# 1. Create feature branch from developgit checkout developgit pull origin developgit checkout -b feature/my-new-feature
# 2. Make changes and pushgit add .git commit -m "Add my new feature"git push -u origin feature/my-new-feature
# 3. Create PR targeting develop# GitHub will show a preview URL in the PRFor Releases to Production:
# 1. Create PR from develop to main# This requires approval due to protection rules
# 2. After approval and merge, production auto-deploysπ¨ Emergency Procedures
If You Need to Push Directly to Production:
- Go to Settings β Branches
- Click edit on the
mainrule - Temporarily uncheck βInclude administratorsβ
- Make your emergency fix
- IMPORTANT: Re-enable the protection immediately
Alternative: Hotfix Branch
# Better approach for emergenciesgit checkout -b hotfix/urgent-fix origin/maingit commit -m "Fix critical bug"git push -u origin hotfix/urgent-fix
# Create PR directly to main# This still requires approval but is trackedπ― Benefits of This Setup
-
No Accidental Production Deployments
- Canβt push directly to main
- All changes require PR and approval
-
Automatic Testing
- GitHub Actions must pass before merge
- Build errors caught before production
-
Code Review
- At least one person reviews changes
- Catches bugs and improves code quality
-
Preview URLs
- Every PR gets a preview link
- Stakeholders can test before approval
-
Staging Environment
- Test in develop before production
- Catch integration issues early
π Status Checks Explained
The βbuild-and-deployβ status check ensures:
- β React app builds successfully
- β No TypeScript errors
- β Dependencies install correctly
- β Deployment configuration is valid
π§ Additional Recommended Settings
1. Add CODEOWNERS File
Create .github/CODEOWNERS:
# Global owners* @LarryAnglin
# Frontend specific/react/ @LarryAnglin
# Backend specific/functions/ @LarryAnglin2. PR Templates
Create .github/pull_request_template.md:
## DescriptionBrief description of changes
## Type of Change- [ ] Bug fix- [ ] New feature- [ ] Breaking change- [ ] Documentation update
## Testing- [ ] Tested locally- [ ] Tested on preview URL- [ ] Tested on staging
## Checklist- [ ] Code follows style guidelines- [ ] Self-review completed- [ ] Comments added for complex code- [ ] Documentation updatedπ Next Steps
- Set up the branch protection rules above
- Create the develop branch
- Try creating a test PR to see the workflow
- Adjust settings based on your teamβs needs
π‘ Tips
- Start with strict rules and relax them if needed
- Use GitHubβs βSuggest changesβ in PR reviews
- Set up notifications for PR reviews
- Use draft PRs for work-in-progress
Remember: These rules are for safety. They can always be adjusted as your needs change!