Git Branching Strategies — Git Flow, GitHub Flow, Trunk-Based
In this tutorial, you'll learn about Git Branching Strategies. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
What You'll Learn
Compare Git branching strategies — Git Flow, Github Flow, and Trunk-Based Development — and choose the right one for your team's release cycle and size.
Why It Matters
A good branching Strategy prevents merge conflicts, keeps deployments safe, and enables parallel development without chaos. A bad one slows everyone down.
Real-World Use
A startup using Github Flow for continuous deployment, an enterprise using Git Flow for quarterly releases, or a SRE team using Trunk-Based for rapid rollbacks.
Git Flow
Classic Strategy with two long-lived branches:
main
└── develop
├── feature/login
├── feature/api
└── release/1.2
git checkout -b develop main
git checkout -b feature/login develop
# ... work ...
git checkout develop
git merge feature/login
# Prepare a release
git checkout -b release/1.2 develop
# ... bug fixes, version bumps ...
git checkout main
git merge release/1.2
git tag v1.2
git checkout develop
git merge release/1.2
Branches: main, develop, feature/*, release/*, hotfix/*
| When | Use |
|---|---|
| Scheduled releases | Quarterly/monthly |
| Multiple versions in production | LTS releases |
| Large teams (20+) | Need structure |
Downside: Complex. Developers often merge wrong branches.
Github Flow
Simpler: everything branches from main:
main
├── feature/login → merge → main → deploy
├── feature/api → merge → main → deploy
└── hotfix/bug → merge → main → deploy
# Everything starts from main
git checkout -b feature/login main
# ... work ...
git push -u origin feature/login
# Open PR on GitHub
# After review, merge to main
git checkout main
git pull
git branch -d feature/login
Rule: main is always deployable.
| When | Use |
|---|---|
| Continuous deployment | Every push to main deploys |
| Small-medium teams | 1-20 developers |
| SaaS products | Single production version |
Trunk-Based Development
Short-lived branches (hours, not days), merge frequently:
main
├── feature-a (few hours) → main
├── feature-b (few hours) → main
├── bugfix (minutes) → main
└── feature-c (few hours) → main
Key rules:
- Branches live < 1 day
- No long-running feature branches
- Feature flags hide incomplete work
- Everyone merges to main multiple times/day
Prerequisite: Good automated test coverage.
| When | Use |
|---|---|
| CI/CD with fast feedback | High test coverage |
| Experienced teams | Comfortable with feature flags |
| Deployment frequency | Multiple deploys/day |
Comparison
| Aspect | Git Flow | Github Flow | Trunk-Based |
|---|---|---|---|
| Complexity | High | Low | Low |
| Branch lifetime | Days-weeks | Days | Hours |
| Releases | Scheduled | Continuous | Continuous |
| Hotfixes | Complex | Simple | Simple |
| Parallel features | Yes | Yes (separate branches) | Yes (feature flags) |
| Merge conflicts | Frequent | Rare | Rare |
| Team size | 20+ | 1-20 | 3-10 |
| Test coverage needed | Moderate | Good | Excellent |
Which to Choose?
Is your product a library with LTS releases?
└── Yes → Git Flow
Do you deploy continuously (SaaS)?
└── Do you have excellent test coverage?
├── Yes → Trunk-Based
└── No → GitHub Flow
Are you a solo developer?
└── GitHub Flow or Trunk-Based
Common Pitfalls
| Mistake | Better Approach |
|---|---|
| Long-lived branches | Merge to main daily |
| Cherry-picking between branches | Fix the root cause |
| Too many branches | Keep it simple (main + feature) |
| No cleanup | Delete merged branches |
| Big bang merges | Merge frequently (small batches) |
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro