Skip to content
BENIBIX Learn

Git Branching Strategies

Level 5 · Working as a team

How teams decide which branches exist and how work gets back to main. Trunk-based development against Git Flow, and where a monorepo fits in.

Course contentsLesson 13 of 13

After this lesson you can

  • Say what a branching strategy decides
  • Compare trunk-based development and Git Flow
  • Pick a strategy for your team

13 mincovers 5 glossary entries

Worth reading first: Branch Protection and Hooks

Trunk-based development or Git Flow

A branching strategy is a team's rules for branches: which ones exist, how long they live, and how work gets back to main. The two best known are trunk-based development and Git Flow. Trunk-based teams merge into main at least once every 24 hours. Git Flow keeps two long-lived branches and three short kinds.

In trunk-based development, everyone works on one main branch, called the trunk. Branches, if any, are tiny and last a day or less. Small changes join often, so conflicts stay small. Tests run on every merge, because a broken trunk breaks everyone at once.

Half-done work still lands on the trunk, hidden behind a feature flag. A feature flag is a switch in the code that keeps a new feature off for users until it is ready. The code ships every day. The feature appears when someone turns the switch on.

Git Flow was set out in a blog post in 2010. Main holds what is live, and develop holds the next release. Feature branches come off develop and merge back into it. A release branch carries develop into main. A hotfix branch fixes main fast, and is merged into both.

Git Flow suits software shipped as numbered versions, such as an app where version 3 and version 4 are both still in use. In 2020 its author added a note to the post. Teams that ship a website many times a day, it says, should use something simpler.

A monorepo is a related choice: one repository that holds many projects. A web app, a phone app and their shared code can sit in one repo, in separate folders. One commit can then change all three at once. The cost is size, so big monorepos need tools that build and test only what changed.

The common mistake is copying a heavy strategy a small team does not need. Five kinds of branch for a team of three means more merging than coding. Start with main plus short feature branches, and add rules only when a real problem shows up.

Two branching strategies side by side

QuestionTrunk-based developmentGit Flow
Long-lived branchesOne: mainTwo: main and develop
How often work joinsAt least once a dayWhen a feature is done
Half-done workHidden behind feature flagsKept on feature branches
SuitsWebsites shipped oftenApps with numbered versions

Which one to pick

  1. 1

    Trunk-based development

    When you ship a website or service many times a week, and your tests are good.

  2. 2

    Git Flow

    When you ship numbered versions, and must keep fixing old ones people still use.

One busy main line, or five kinds of branch. Fewer and shorter branches mean fewer conflicts.

Worked example

A team of 4 drops Git Flow

Jack's team of 4 runs a shopping website and uses Git Flow. Each finished feature waits about 2 weeks for the next release branch.

They switch to trunk-based development with feature flags. Changes now reach the site the same day, and the long merge on release day is gone.

The words for this lesson5

Check yourself

How do trunk-based teams ship code for a feature that is not finished?

Finished this lesson?

Marking it complete also marks its 5 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.