Branching models
Last updated
Every team decides how branches are used: how long they live, where work goes, how releases are made. The common recipes have names: GitHub Flow, trunk-based development, Git Flow. In this lesson you'll see the same month of Kusina work in each, and learn which suits which kind of team.
By the end of this lesson you can
- Describe GitHub Flow, trunk-based development and Git Flow
- Explain feature flags and why trunk-based teams use them
- Choose a model for a team, with a reason
GitHub Flow
The simplest common model, and the one this course has used:
- main is always in a good state: printable, deployable.
- For each change, make a short branch from main.
- Commit, push, open a pull request, get it reviewed (and checked, lesson 7.3).
- Merge to main, and delete the branch. Release from main, often.
A month of Kusina in GitHub Flow: a few short loops off one line.
* Merge pull request #9 from carla/add-palabok |\ | * Add pancit palabok recipe |/ * Merge pull request #8 from ana/fix-flan-eggs |\ | * Use 12 egg yolks in the leche flan |/ * Merge pull request #7 from joaquin/index-desserts |\ | * Include the desserts folder in the index | * List recipes in alphabetical order |/ * Add halo-halo recipe
Trunk-based development
Everyone integrates into one branch, the trunk (main), at least once a day: either committing straight to it, or through branches that live a day or two at most. Changes are small, and automated checks run on every one.
What about a feature that takes three weeks? It's merged bit by bit, switched off behind a feature flag: a setting in the code that hides it until it's finished. The code is in main the whole time, so nobody's branch drifts far, and conflicts stay small.
* Show the photo gallery (flag on) * Use 12 egg yolks in the leche flan * Gallery: add captions (flag off) * Add pancit palabok recipe * Gallery: first version, behind a flag (flag off) * Include the desserts folder in the index
trunkbaseddevelopment.com describes it in full. Many large companies work this way, along with continuous integration (Simple Software Development 7.2).
Git Flow, and its author's note
Git Flow (Vincent Driessen, 2010) uses two long-lived branches and three kinds of short ones:
- main: only released versions, each tagged;
- develop: where finished features gather for the next release;
- feature/… branches from develop; release/… branches to prepare a release; hotfix/… branches from main for urgent fixes, merged into both.
* (main, tag: v1.1) Merge branch 'release/1.1' |\ | * (develop) Merge branch 'feature/palabok' into develop | |\ | | * Add pancit palabok recipe | |/ | * Bump version to 1.1 |/ * (tag: v1.0.1) Merge branch 'hotfix/flan-eggs' |\ | * Use 12 egg yolks in the leche flan |/ * (tag: v1.0) Release 1.0
It suits software released as numbered versions that must be supported side by side, like apps in a store. In 2020 Driessen added a note to his article: for software that's delivered continuously, like most websites, he recommends a much simpler workflow such as GitHub Flow instead.
Release branches
Any model can add release branches: when a version is ready, branch release-1 from main, and fix only bugs on it (often by cherry-picking fixes from main, as in lesson 6.6). main carries on with new work. Kusina's printed edition, in 6.6, used one.
Which one?
| GitHub Flow | Trunk-based | Git Flow | |
|---|---|---|---|
| Long-lived branches | main | main | main and develop |
| How long branches live | Days | Hours to a day or two | Days to weeks |
| Releases | From main, often | From main, often (or release branches) | release/ branches, tagged on main |
| Suits | Most teams, websites, small projects | Teams with strong automated checks, deploying many times a day | Numbered versions supported side by side |
| Needs | Reviews and a working main | Feature flags, CI, discipline about small changes | Everyone knowing the rules for five kinds of branch |
Spot the trap: Git Flow for two people
Ana reads about Git Flow and sets it up for Kusina: develop, feature branches, release branches, hotfixes. Kusina is updated whenever someone types up a recipe, and the website rebuilds from main.
What happens if…
Check what you learned
Sources
Every command on this page behaves as these pages describe, and the sandbox prints what Git 2.55 prints. Hosting features (pull requests, protected branches) come from the host’s own documentation.
- GitHub Docs: GitHub flow: branch, commit, pull request, review, merge, delete
- Trunk Based Development (Paul Hammant and contributors): short-lived branches, feature flags, release branches
- A successful Git branching model (Vincent Driessen, 2010), with his note of reflection (2020): Git Flow, and its author recommending simpler models for continuously delivered software
- Pro Git: Branching Workflows: long-running and topic branches