Why a Branching Strategy?
Without a strategy, teams end up with merge conflicts, broken main branches, and confusion about what's deployed where.
GitHub Flow (Simple)
Best for: small teams, continuous deployment
main ──●──●──●──●──●──●──●──●──●──
\ / \ /
●──● ●──●──●
feature-a feature-b
Rules:
mainis always deployable- Create feature branches from
main - Open a pull request when ready
- After review and CI passes, merge to
main - Deploy
mainimmediately
# Start a feature
git checkout -b feature/user-auth main
# Work, commit, push
git add .
git commit -m "Add user authentication"
git push -u origin feature/user-auth
# Open PR, get review, merge
GitFlow (Structured)
Best for: teams with scheduled releases
main ──●──────────────●──────●──
\ / \ /
develop ──●──●──●──●──● ●──●
\ / release
●──●
feature
Branches:
| Branch | Purpose | Merges Into |
|--------|---------|-------------|
| main | Production code | — |
| develop | Integration | main (via release) |
| feature/* | New features | develop |
| release/* | Release prep | main + develop |
| hotfix/* | Emergency fixes | main + develop |
Trunk-Based Development
Best for: experienced teams with strong CI/CD
main ──●──●──●──●──●──●──●──●──
\/ \/ \/ \/
Short-lived branches (< 1 day)
Rules:
- Everyone commits to
main(or very short-lived branches) - Feature flags hide incomplete work
- Requires excellent CI and test coverage
Commit Message Convention
type(scope): description
feat(auth): add two-factor authentication
fix(api): handle null response from payment provider
docs(readme): update deployment instructions
refactor(db): extract connection pooling logic
test(auth): add integration tests for login flow
chore(deps): update dependencies
Branch Protection Rules
Configure on GitHub/GitLab:
- Require pull request reviews (1-2 approvers)
- Require status checks to pass (CI/tests)
- Require branches to be up to date
- Prevent force pushes to
main
Tip For most teams, GitHub Flow is the right starting point. Only adopt GitFlow if you have scheduled release cycles. Trunk-based is powerful but requires mature testing practices.