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:
- Branch off
main:feature/search. - Commit and push, as often as needed.
- Open a pull request, and get it reviewed and tested.
- Merge into
main, and deploy.
main ●─────────────●──────────────●
\ / \ /
feature/ ●───●───● ●──────●
search fix/cart-totalSimple 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:
| Branch | Purpose | Branches from → merges into |
|---|---|---|
main | Only released versions, each one tagged | — |
develop | The next release, being built | — |
feature/* | One new feature | develop → develop |
release/* | Final testing and fixes for a version | develop → main and develop |
hotfix/* | An urgent fix to the live version | main → 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.
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 Flow | Git Flow | Trunk-based | |
|---|---|---|---|
| Long-lived branches | main | main, develop | main |
| Feature branches last | Days | Days to weeks | Hours, or none |
| Releases | Every merge can deploy | Planned versions | Continuous |
| Needs | Pull requests | Discipline about merging | Strong tests, feature flags |
| Fits | Most web apps and small teams | Versioned products | Experienced teams that deploy often |
Branch names
Most teams name short branches by type, with a slash:
| Prefix | For | Example |
|---|---|---|
feature/ | New features | feature/dark-mode |
fix/ | Bug fixes | fix/12-cart-total |
chore/ | Upkeep: dependencies, config | chore/update-next |
docs/ | Documentation | docs/setup-guide |
hotfix/ | Urgent fixes to production | hotfix/login-crash |
Lowercase with hyphens, short, and with the issue number when there is one.