Opscraft
Git · Lesson 6 of 8 · 4 min read

Branching strategies

Trunk-based development

Everyone integrates into main (trunk) at least daily via short-lived branches (hours to a couple of days). Main is always releasable; incomplete features hide behind feature flags; releases are tags (or short release branches cut from main).

Enlarge diagramshort branchv1.4v1.5mainFeature flags hide unfinished work, so main is always releasable.
Figure 1. Trunk-based development: short-lived branches merge into main within a day or two, and releases are tags on main.
Swipe sideways to see all of it, or tap to open it full screen.
  • Pros: minimal merge conflicts, true continuous integration, fast feedback, fits continuous delivery and GitOps.
  • Needs: strong automated tests, fast CI, feature flags, discipline about small changes.
  • Strongly correlated with high delivery performance in the DORA research.

GitFlow

Long-lived main (production) and develop branches, plus feature/*, release/* and hotfix/* branches with prescribed merges between them.

Enlarge diagrammainhotfixreleasedevelopfeaturev1.0v1.0.1
Figure 2. GitFlow: long-lived main and develop branches, plus feature, release and hotfix branches. Structured, but heavy for continuous delivery.
Swipe sideways to see all of it, or tap to open it full screen.
  • Pros: structure for versioned, scheduled releases (packaged software, mobile apps, multiple supported versions).
  • Cons: heavy, long-lived branches, big merges, slow integration — generally considered a poor fit for web services doing continuous delivery. Even its author later recommended simpler flows for continuously delivered software.

GitHub flow

Branch from main → PR → review + CI → merge → deploy main. Essentially trunk-based with PRs; a sensible default for most service teams.

Release branches

Cut release/1.4 from main when you need to stabilise or maintain a version; fix on main first and cherry-pick to the release branch (or the reverse, but be consistent). Useful for on-prem products or regulated release trains.

Environment branches: an anti-pattern in GitOps

Having dev, staging, prod branches in a GitOps config repo and merging between them tends to cause drift, confusing merges and accidental promotion of unrelated changes. The common recommendation is one branch with a directory per environment (Kustomize overlays: overlays/dev, overlays/prod) and promotion by changing values in the next environment's directory via PR.

Enlarge diagramA branch per environmentA folder per environmentdev, staging and prod branches drift apartMerging dev → prod drags along unrelatedchangesHard to see what differs between environmentsOne main branch: base/ plus overlays/dev,staging, prodPromotion is a small PR changing one valuegit diff between folders shows every difference
Figure 3. For GitOps config, use folders per environment on one branch, not a branch per environment.
Swipe sideways to see all of it, or tap to open it full screen.

Versioning and releases

  • Semantic versioning MAJOR.MINOR.PATCH: breaking change → major, new feature → minor, fix → patch.
  • Tag releases (v1.4.0, annotated and ideally signed); CI builds release artifacts from tags.
  • Automate with Conventional Commits + tools like semantic-release or release-please (generates the changelog and version bump from commit messages).
  • Container images: tag with the commit SHA for traceability, plus the semver tag for releases.
Enlarge diagramMAJORMINORPATCHbreaking change1.4.2 → 2.0.0new feature, backward compatible1.4.2 → 1.5.0bug fix only1.4.2 → 1.4.3..
Figure 4. Semantic versioning: the number tells users how risky an upgrade is.
Swipe sideways to see all of it, or tap to open it full screen.