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 -> deploy

Git 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-description or feature/JIRA-123-short-description
  • fix/login-timeout, hotfix/payment-rounding
  • chore/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 steps

Benefits: 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

  1. Require pull requests – no direct pushes.
  2. Require passing CI (build, tests, lint, security scan).
  3. Require at least one reviewer (two for sensitive code).
  4. Require branches to be up to date before merging.
  5. 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 something

How 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.