Skip to content
Laviyx Learn

Try

Git and GitHub course menu

Git Workflows Compared: GitHub Flow, Git Flow and Trunk-Based

Compare GitHub Flow, trunk-based development and Git Flow: how each one works, when to use it, how teams handle hotfixes and releases, and which to choose.

Intermediate3 min readUpdated
On this page

Git allows almost any way of working, so each team agrees on a workflow: rules for which branches exist and how code reaches production. Interviewers often ask about these three.

GitHub Flow#

The simplest workflow, and a good default for web apps and small teams.

Text
main  ----o-------o-------o------   (always deployable)
           \     /
            o---o   feature/cart  (pull request)
  1. main is always ready to deploy.
  2. Create a short-lived branch for every change.
  3. Open a pull request, get it reviewed, and let the tests run.
  4. Merge into main and deploy.

It suits teams that deploy often and have one live version of the product.

Trunk-based development#

Everyone integrates into one main branch (the "trunk") very often, at least daily. Branches last hours rather than weeks, or developers commit directly with strong automated tests.

Unfinished features are hidden behind feature flags: the code is merged but switched off, so it can reach production safely.

Python
if flags.is_enabled("new_checkout", user):
    show_new_checkout()
else:
    show_old_checkout()

This avoids long-lived branches and painful merges, but it needs good automated testing. Many large companies work in this way.

Git Flow#

An older, more formal workflow with several permanent branches, designed for software with planned releases.

BranchPurpose
mainReleased code only, tagged with versions
developWhere features are combined
feature/*One feature, branched from develop
release/*Final testing before a release
hotfix/*Urgent fix, branched from main

It suits products with scheduled versions, or several versions supported at the same time, such as installed desktop software. For web apps that deploy daily, it is usually more process than you need.

Comparison#

GitHub FlowTrunk-basedGit Flow
Long-lived branchesmainmainmain, develop
Branch lifetimeDaysHoursDays to weeks
ReleasesContinuousContinuousScheduled
Needs strong testsYesEssentialHelpful
ComplexityLowLow process, high disciplineHigh

Hotfixes#

Something is broken in production. In GitHub Flow, create a branch from main, fix the problem, and merge through a quick pull request. In Git Flow, branch from main, then merge the fix into both main and develop.

If a project keeps release branches for old versions, the fix is often cherry-picked from main to those branches.

Rules that help every workflow#

  • Keep branches short-lived.
  • Protect main, and require reviews and passing checks.
  • Merge small changes often.
  • Use the same merge style across the team.

Practice#

Practice exercise

A mobile app is released to app stores every two weeks, and old versions must get bug fixes for a few months. A website team deploys five times a day. Which workflows would you suggest?

Show solution

The mobile app has scheduled releases and several supported versions, so Git Flow or a simpler variant with release branches fits. The website has one live version and deploys constantly, so GitHub Flow or trunk-based development fits better.

Key takeaway#

Next: CI with GitHub Actions.

Finished this lesson?