Canary Branch Workflow
Follow this guide to use the canary branch for testing before merging to main. The canary branch is a pre-main integration branch where changes are tested together before full deployment.
What is Canary Branch?
The canary branch is a testing branch that sits between feature branches and main:
- Feature branches merge into
canaryfor integration testing - When
canaryis stable, it merges intomain mainis always deployable and reflects production
feature/xyz → canary → main
Canary Workflow
Step 1: Create Feature Branch
git checkout -b feat/my-feature
# Make your changes
git add -A
git commit -m "feat(skills): add new feature
Testing new capability before main.
Co-Authored-By: martyy-code <nesalia.inc@gmail.com>"
Step 2: Push to Remote
git push -u origin HEAD
Step 3: Create PR to Canary
gh pr create --title "feat(skills): add new feature" --body "## Summary
- New feature for testing
## Test Plan
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed
Co-Authored-By: martyy-code <nesalia.inc@gmail.com>" --base canary
Step 4: Merge to Canary
After PR approval, merge to canary:
gh pr merge --squash --delete-branch
Step 5: Verify on Canary
# Switch to canary and pull latest
git checkout canary && git pull
# Deploy canary or run tests
./scripts/deploy-canary.sh
# or
npm run test:integration
Step 6: Monitor and Validate
# Check canary build status
gh run list --branch canary
# View canary logs
kubectl logs -l environment=canary
Step 7: Merge Canary to Main
Once canary is stable:
# From main, merge canary
git checkout main && git pull
git merge origin/canary
# Push main
git push
Branch Protection Rules
| Branch | Protection |
|---|---|
main |
Requires PR, require status checks, no force push |
canary |
Requires PR, require status checks, no force push |
Canary vs Main
| Aspect | Canary | Main |
|---|---|---|
| Purpose | Integration testing | Production-ready |
| Stability | Testing/stable | Always deployable |
| Frequency | Regular merges from features | Merged from canary when stable |
| Deploys | Staging/beta environments | Production |
Integration with CI/CD
Canary triggers CI pipelines to validate integration:
# .github/workflows/canary-ci.yml
name: Canary CI
on:
push:
branches: [canary]
jobs:
test:
runs-on: ubuntu-latest
steps:
- checkout
- run: npm ci
- run: npm test
- run: npm run build
Quick Reference
Create feature branch: git checkout -b feat/my-feature
Push feature: git push -u origin HEAD
Create PR to canary: gh pr create --base canary
Merge to canary: gh pr merge --squash
Verify canary: git checkout canary && git pull
Merge canary to main: git checkout main && git merge origin/canary && git push
Common Mistakes to Avoid
- Direct push to canary: Always use PR for canary merges
- Skip testing on canary: Never merge canary to main without validation
- Outdated canary: Keep canary synced with main regularly
- Bypass CI: Don't merge if CI is failing on canary
- Merge conflicts: Resolve conflicts on feature branch before PR
Related Skills
| Skill | When to Use |
|---|---|
/commit |
Make commits following conventions |
/pr-creation |
Create PRs to canary or main |
/sync |
Keep branches up to date |
/push |
Push changes and create PRs |