Quick answer: For most modern teams that deploy often, trunk-based development or GitHub Flow (short-lived feature branches merged into main through pull requests, with CI and feature flags) is the best choice. Git Flow (develop, release and hotfix branches) suits products with planned, versioned releases β such as installed software or mobile apps with store reviews. Whatever you choose, keep branches short-lived and protect main.
A branching strategy is a team agreement on how code moves from a developer's laptop to production. A bad strategy causes painful merges, broken releases and blocked teams. This guide compares the main options and gives practical rules you can adopt today.
The three main strategies
Strategy | Branches | Best for | Watch out for |
|---|---|---|---|
Trunk-based | main + very short branches (hours to 1β2 days) | Continuous delivery, experienced teams, strong CI | Needs feature flags and good tests |
GitHub Flow | main + feature branches + pull requests | Web apps and APIs deployed frequently | Long-lived branches drift |
Git Flow | main, develop, feature/*, release/*, hotfix/* | Versioned releases, multiple supported versions | Complex; slow for daily deploys |
GitHub Flow in practice
git switch main && git pull
git switch -c feature/invoice-pdf
# ...work, commit small steps...
git add -A && git commit -m "feat(invoice): generate PDF with QR code"
git push -u origin feature/invoice-pdf
# open Pull Request -> CI runs -> review -> squash merge -> deployGit Flow in practice
feature/* βββΊ develop βββΊ release/1.4.0 βββΊ main (tag v1.4.0)
β²
hotfix/1.4.1 βββββββββββ main ββββββ (merged back to develop too)Use it when you must stabilise a release for weeks (QA cycles, app store review) while development continues.
Naming conventions
feature/short-descriptionorfeature/JIRA-123-short-descriptionfix/login-timeout,hotfix/payment-roundingchore/upgrade-dependencies,docs/api-readme
Commit messages that help
Use Conventional Commits: type(scope): summary
feat(auth): add passkey login
fix(cart): prevent negative quantity
refactor(orders): extract pricing service
docs(readme): add local setup stepsBenefits: readable history, automatic changelogs and semantic version bumps.
Merge vs rebase vs squash
- Merge commit β keeps full history including branch structure; can be noisy.
- Rebase β linear history; never rebase shared branches others are using.
- Squash merge β one clean commit per pull request on main; most popular for GitHub Flow.
Protect your main branch
- Require pull requests β no direct pushes.
- Require passing CI (build, tests, lint, security scan).
- Require at least one reviewer (two for sensitive code).
- Require branches to be up to date before merging.
- Use CODEOWNERS for critical folders.
Feature flags: the secret to small branches
Merge unfinished features hidden behind a flag instead of keeping a branch open for weeks:
if (features.isEnabled('new-checkout', user)) {
return renderNewCheckout();
}
return renderOldCheckout();Remove old flags regularly so they do not become technical debt.
Pull request best practices
- Keep PRs small (under ~400 changed lines when possible).
- Write a clear description: what, why, how to test, screenshots.
- Link the ticket.
- Reviewers: be kind and specific; authors: respond to every comment.
Useful rescue commands
git stash / git stash pop # park unfinished work
git commit --amend # fix last commit (before pushing)
git revert <sha> # undo a pushed commit safely
git reflog # find "lost" commits
git cherry-pick <sha> # copy a fix to another branch
git bisect start # find the commit that broke somethingHow to choose
- Deploy several times a day/week? β Trunk-based or GitHub Flow.
- Scheduled versioned releases or several supported versions? β Git Flow (or release branches only).
- Small team, new to Git? β GitHub Flow β simple and safe.
Summary
- Short-lived branches + protected main + CI = fewer problems.
- Use Conventional Commits and squash merges for clean history.
- Feature flags let you merge early and release safely.
- Pick the simplest strategy that matches how often you release.