Git Branching Strategies Explained
Short answer: a branching strategy is the team's agreed rule for how branches are created, named, reviewed and merged. The three most common are GitHub Flow (simple, one main branch plus short-lived feature branches), Git Flow (separate develop and release branches) and trunk-based development (everyone merges to main very often). Most teams are best served by GitHub Flow or trunk-based development.
Why you need a strategy
Without rules, branches live for weeks, merges become painful and nobody knows which branch is safe to release. A shared strategy makes releases predictable, code review consistent and conflicts smaller. If you are new to branches, read Git basics first.
1. GitHub Flow
main o---o-------o-------o
\ / \ /
feature o---o o---o
mainis always deployable.- Create a short-lived branch for each change (
feature/login-form). - Commit and push, then open a pull request; see pull requests explained.
- After review and passing tests, merge into
main. - Deploy from
main.
Best for: web apps and services that deploy continuously. Downside: no built-in support for maintaining several released versions at once.
2. Git Flow
| Branch | Purpose |
|---|---|
main | Production releases only, tagged with versions |
develop | Integration branch for the next release |
feature/* | New features, branched from and merged into develop |
release/* | Stabilizing a release (bug fixes only) |
hotfix/* | Urgent production fixes, branched from main |
Best for: software with scheduled releases and multiple supported versions, such as mobile apps, desktop software and libraries. Downside: more branches and ceremony, and long-lived branches increase merge conflicts.
3. Trunk-based development
Developers commit to a single branch (the trunk, usually main) at least daily, either directly or through very short-lived branches. Incomplete work is hidden behind feature flags so it can ship without being visible. It depends on strong automated testing and CI.
Best for: mature teams with good test coverage practicing continuous delivery. Downside: needs discipline, fast CI and feature flags.
Comparison
| GitHub Flow | Git Flow | Trunk-based | |
|---|---|---|---|
| Complexity | Low | High | Low (but needs discipline) |
| Branch lifetime | Days | Days to weeks | Hours to a day |
| Release style | Continuous | Scheduled | Continuous |
| Multiple versions | Awkward | Supported | Use release branches only if needed |
| Needs strong CI | Yes | Helpful | Essential |
Branch naming conventions
feature/user-profile
bugfix/cart-total-rounding
hotfix/payment-timeout
release/2.4.0
chore/update-dependencies
Use lowercase and hyphens, and include a ticket ID if your team tracks work that way (feature/PROJ-123-login).
Merge methods
- Merge commit: preserves all history and shows when branches joined.
- Squash and merge: turns the branch into one tidy commit.
- Rebase and merge: a linear history; see merge vs rebase.
Good practices for any strategy
- Keep branches small and short-lived.
- Require pull requests, reviews and passing checks before merging; automate with GitHub Actions.
- Protect
mainso nobody can push to it directly or force-push. - Update your branch from
mainoften to avoid large conflicts; see resolving conflicts. - Delete branches after merging.
How to choose
- Small team, web product, deploy often: GitHub Flow.
- Versioned releases and long support windows: Git Flow, or GitHub Flow plus release branches.
- Experienced team with fast CI and feature flags: trunk-based.
- Not sure: start with GitHub Flow and add structure only when you feel a specific pain.
FAQs
Is Git Flow outdated?
The author of Git Flow has said it suits software with explicit versions, but is not ideal for continuously delivered web apps. It is still valid where that fits.
How long should a feature branch live?
As short as possible, ideally a few days at most. Long branches are the main cause of painful merges.
What are feature flags?
Switches in code that turn a feature on or off without redeploying, letting unfinished work be merged safely.
Do I need a develop branch?
Only if you use Git Flow or need a staging integration branch. Many teams work well with just main.
