Git and GitHub · Part 4 · Team workflows

Branching strategies

Agreeing how to branch

Git lets anyone make any branch, at any time. On a team, that freedom needs a shared plan: where new work starts, where it goes when it's done, and which branch is safe to deploy. That plan is a branching strategy. Three are common, from simplest to most structured.

GitHub Flow

One long-lived branch, main, which is always ready to deploy. Everything else is a short branch:

  1. Branch off main: feature/search.
  2. Commit and push, as often as needed.
  3. Open a pull request, and get it reviewed and tested.
  4. Merge into main, and deploy.
Branches
main      ●─────────────●──────────────●
           \           /  \            /
feature/   ●───●───●       ●──────●
search                     fix/cart-total

Simple to learn and fits websites and apps that deploy often. It is everything the earlier lessons did, and it's where most teams start.

Git Flow

Published by Vincent Driessen in 2010, for software released in numbered versions. It uses two long-lived branches and three kinds of short ones:

BranchPurposeBranches from → merges into
mainOnly released versions, each one tagged—
developThe next release, being built—
feature/*One new featuredevelop → develop
release/*Final testing and fixes for a versiondevelop → main and develop
hotfix/*An urgent fix to the live versionmain → main and develop

It gives a clear place for every kind of work, which suits desktop or mobile apps with scheduled releases, or several supported versions at once. For a website that deploys every day, it's a lot of merging for little gain; even its author now recommends something simpler in that case.

Trunk-based development

Everyone integrates into main (the “trunk”) at least once a day. Branches live for hours, not weeks, or people commit straight to main with strong automated tests.

Unfinished features still go in, hidden behind a feature flag: an on/off switch in the code.

A feature flag
if (flags.newCheckout) {
  return <NewCheckout />;
}
return <OldCheckout />;

Merge conflicts stay tiny, because nobody drifts far from main. It needs good tests and discipline, and is used by large companies that deploy many times a day.

Side by side

GitHub FlowGit FlowTrunk-based
Long-lived branchesmainmain, developmain
Feature branches lastDaysDays to weeksHours, or none
ReleasesEvery merge can deployPlanned versionsContinuous
NeedsPull requestsDiscipline about mergingStrong tests, feature flags
FitsMost web apps and small teamsVersioned productsExperienced teams that deploy often

Branch names

Most teams name short branches by type, with a slash:

PrefixForExample
feature/New featuresfeature/dark-mode
fix/Bug fixesfix/12-cart-total
chore/Upkeep: dependencies, configchore/update-next
docs/Documentationdocs/setup-guide
hotfix/Urgent fixes to productionhotfix/login-crash

Lowercase with hyphens, short, and with the issue number when there is one.