Git Branching Strategies
Git Branching Strategies
Section titled “Git Branching Strategies”A branching strategy defines how your team uses branches to manage development, releases, and hotfixes. The right strategy depends on your release cadence and team size.
GitHub Flow (Recommended for Most Teams)
Section titled “GitHub Flow (Recommended for Most Teams)”Simple, effective for continuous delivery:
main (always deployable) └── feature/user-auth ← branch from main └── fix/login-bug ← merge back to main via PR └── feature/dashboardWorkflow:
- Branch from
main - Write code, commit frequently
- Open a pull request
- Review and CI runs
- Merge to
main - Deploy from
main
git switch main && git pullgit switch -c feature/user-auth# ... commit changes ...git push -u origin feature/user-auth# Open PR on GitHub → Review → MergeGood for: teams deploying continuously (multiple times per day), SaaS products, open-source projects.
Git Flow
Section titled “Git Flow”More structured, suited for versioned releases:
main ← released code onlydevelop ← integration branch├── feature/* ← branch from develop├── release/* ← branch from develop when ready to release└── hotfix/* ← branch from main for urgent fixesBranches:
main— production-ready, tagged with versionsdevelop— integration of completed featuresfeature/name— new features, branch fromdeveloprelease/1.2.0— release preparation (bug fixes, docs), branch fromdevelop, merge intomainanddevelophotfix/name— urgent production fixes, branch frommain, merge intomainanddevelop
# Start a featuregit switch develop && git pullgit switch -c feature/payment-gateway
# Finish featuregit switch developgit merge --no-ff feature/payment-gatewaygit branch -d feature/payment-gateway
# Start a releasegit switch -c release/1.2.0 develop# bump version, update changelog...git switch main && git merge --no-ff release/1.2.0git tag -a v1.2.0 -m "Version 1.2.0"git switch develop && git merge --no-ff release/1.2.0Good for: apps with scheduled releases, multiple supported versions, mobile apps with app store submissions.
Trunk-Based Development
Section titled “Trunk-Based Development”Everyone commits to main (trunk) at least once per day. Very short-lived branches (hours, not days):
main ← all developers commit here frequentlyFeature work is hidden behind feature flags until ready. Requires a strong CI/CD pipeline and good test coverage.
Good for: large, experienced teams with mature CI/CD (Google, Facebook style).
Comparison
Section titled “Comparison”| Strategy | Best for | Release cadence | Complexity |
|---|---|---|---|
| GitHub Flow | Most teams | Continuous | Low |
| Git Flow | Versioned releases | Scheduled | Medium |
| Trunk-Based | Large teams, mature CI | Continuous | High |
Branch Naming Conventions
Section titled “Branch Naming Conventions”feature/user-authenticationfeature/JIRA-123-payment-gatewayfix/login-redirect-bughotfix/critical-security-patchchore/upgrade-dependenciesdocs/api-referencerelease/2.1.0Consistent naming makes branches scannable and enables automation (e.g., auto-linking to issue trackers).
Pull Request Best Practices
Section titled “Pull Request Best Practices”- Keep PRs small — 200–400 lines is ideal. Reviewers review larger PRs less carefully
- One concern per PR — a refactor and a feature in one PR are hard to review
- Write a good description — what changed and why, not just what
- Link to the issue —
Closes #123auto-closes the issue on merge - Don’t rebase PRs under review — it makes review history harder to follow
Protecting Main
Section titled “Protecting Main”On GitHub, protect the main branch:
- Require pull request reviews before merging
- Require status checks to pass (CI)
- Prevent force pushes
- Require branches to be up to date before merging