Lesson 14 intermediate

Git Workflows

Compare the branching strategies teams actually use: trunk-based development with feature flags, GitHub flow, GitLab flow with environment branches, Git Flow with develop and release branches, release branches for maintained versions, and how to choose one for your team and your deploy pipeline.

Git does not tell a team how to use branches. A workflow is the agreement: which branches exist, where new work starts, how it gets reviewed and how it reaches production. The right choice depends mostly on one question: how often do you deploy? This lesson compares the four workflows you will meet and shows which one fits Orbit.

Trunk-based development

Everyone integrates into one branch, main (the “trunk”), at least once a day. Branches, if used, live for hours, not weeks.

main  --o--o--o--o--o--o--o--o-->    deploy from main, many times a day
         \_/   \_/    \_/
       short-lived branches (hours)
  • Unfinished features are merged early but hidden behind feature flags, switched on when ready.
  • main must always be deployable, so strong CI is required: every merge runs the full test suite.
  • Merge conflicts stay tiny because nobody drifts far from main.

Trunk-based development is what high-performing teams in the DORA research use most, and it is the natural fit for continuous deployment.

GitHub flow

A lightweight, popular version of the same idea, built around pull requests (lesson 11):

  1. main is always deployable.
  2. Create a descriptively named branch from main.
  3. Commit and push; open a pull request early.
  4. Review and CI on the pull request.
  5. Merge to main and deploy right away.

It has one long-lived branch and nothing else. It works best for web services and SaaS products that run one version in production.

GitLab flow: environment branches

Some teams cannot deploy every merge straight to production: there is a staging sign-off, a change window or a regulator. GitLab flow adds environment branches downstream of main:

main ----o----o----o----o--->        merged features
              \         \
staging -------o---------o--->       deployed to staging
                \
production -------o--------->        deployed to production after approval

Changes always flow one way: merged to main, then promoted to staging, then to production, through merge requests. Fixes go to main first and are promoted or cherry-picked forward, never made directly on production. A popular alternative to environment branches is promoting the same build artifact with tags and deployment approvals in the pipeline.

Git Flow

Git Flow (2010) uses two long-lived branches and three kinds of short-lived ones:

BranchPurposeMerged into
mainReleased versions only, each tagged(nothing)
developIntegration of finished featuresrelease/*
feature/*One feature, from developdevelop
release/*Stabilise a version, only fixesmain and develop
hotfix/*Urgent fix to production, from mainmain and develop

It fits software with scheduled, versioned releases: desktop apps, libraries, firmware, products that customers install. For a web service deployed many times a day, it adds overhead and long-lived branches with painful merges. Even its author added a note recommending simpler flows for continuously delivered software.

Release branches for maintained versions

If you support several versions at once, for example Orbit 1.x for enterprise customers while 2.x is current, add release branches to any of the flows above:

$ git switch -c release/1.4 v1.4.0
$ git cherry-pick -x 3e8a1f0          # back-port a security fix from main
$ git tag -a v1.4.1 -m "Orbit 1.4.1"
$ git push origin release/1.4 v1.4.1

Fix on main first, then cherry-pick to each supported release branch (lesson 12). That way no fix is ever lost in the next version.

Comparing the workflows

Trunk-basedGitHub flowGitLab flowGit Flow
Long-lived branchesmainmainmain + environmentsmain + develop
Branch lifetimeHoursHours to daysDaysDays to weeks
Deploy frequencyMany per dayPer mergePer promotionPer release
Needs feature flagsYesHelpfulHelpfulNo
CI maturity neededHighMedium to highMediumLow to medium
Best forContinuous deploymentWeb apps, SaaSStaged or regulated releasesVersioned, installed software

Choosing for Orbit

Orbit is a web app with a good test suite and a pipeline that deploys in minutes. The team picks GitHub flow with trunk-based habits:

  • Branches from main, merged within a day or two through pull requests.
  • Squash merges, so main reads as one commit per change.
  • Feature flags for anything that cannot ship in two days.
  • Deploy on every merge to main; version tags for each production release.
  • A release/1.x branch only while enterprise customers still run 1.x.

Whatever you pick, write it down in CONTRIBUTING.md and enforce it with branch protection. A workflow only works if everyone follows the same one.

Quick reference

If your team…Consider
Deploys many times a day with strong CITrunk-based development
Ships a web app through pull requestsGitHub flow
Needs staging sign-off before productionGitLab flow or artifact promotion
Ships numbered versions customers installGit Flow or release branches
Supports several versions at onceRelease branches plus cherry-picks

Exercise

Orbit deploys to production after every merge to main and has thorough automated tests. Which workflow fits best?

  1. Git Flow with develop and release branches
  2. One long-lived branch per developer
  3. GitHub flow or trunk-based development
  4. Environment branches for every developer
Show answer

Answer: C. With continuous deployment and good tests, short-lived branches merged into an always-deployable main keep integration simple. Git Flow’s extra branches add delay without benefit here.

Exercise

In trunk-based development, a feature needs three weeks of work but branches should live less than a day. How do teams handle that?

  1. They make an exception and keep a three-week branch
  2. They commit directly to production
  3. They put the work in a stash until it is ready
  4. They merge small pieces to main often and hide the unfinished feature behind a feature flag
Show answer

Answer: D. Feature flags separate deploying code from releasing a feature. Unfinished code ships turned off, so main stays deployable and branches stay short.

Exercise

Your company sells a self-hosted product with versions 3.2 and 4.0 under support. A security bug affects both. Where do you fix it first?

  1. On main, then cherry-pick the fix to each supported release branch
  2. On release/3.2, then merge 3.2 into main
  3. Only on main, because old versions are not maintained
  4. On a new long-lived branch called security
Show answer

Answer: A. Fixing main first guarantees the fix is in every future version. Cherry-picking it to release/3.2 and release/4.0 then produces patch releases for supported customers.

Key takeaways

  • A workflow is the team’s agreement on branches, review and release; it should follow how often you deploy.
  • Trunk-based development and GitHub flow keep one long-lived branch and short-lived feature branches.
  • GitLab flow adds environment branches or promotions for staged releases; changes flow one way.
  • Git Flow suits versioned, installed software and is heavy for continuous deployment.
  • Release branches plus cherry-picks maintain old versions; document the workflow and enforce it with protection rules.

FAQ

Is Git Flow outdated?

Not for what it was designed for: products with planned, numbered releases. It is a poor fit for web services deployed continuously, which is most of what DevOps teams run today. Use it only if your release process actually needs a develop branch.

What is a feature flag?

A switch, read at runtime from configuration or a flag service, that turns a feature on or off without a deploy. It lets unfinished work be merged and deployed safely, and lets you roll out to a few users first.

Do we need a develop branch?

Only if you need a place where finished features wait for a scheduled release. If every merge to main can be deployed, a develop branch only adds a second merge and a second place for conflicts.

How does GitOps change the workflow?

In GitOps, a repository describes what runs in each environment, and a controller such as Argo CD or Flux applies it. Promotion becomes a pull request that changes an image tag in the environment’s folder or branch, so the Git history is the deployment history.

What should a CONTRIBUTING.md say about the workflow?

Where branches start, how to name them, the commit message format, how to open and size a pull request, the merge method and who approves. Short and specific beats long and vague.

↑ ↓ navigate Enter open Esc close