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