TExcelTAD
Home › Release Engineering & CI/CD › Release Branches & Hotfixes

Release Branches & Hotfixes

If every commit on main is releasable and you release from main directly, you don't need release branches; many web services work that way ("trunk-based development"). As soon as you support a released version while main moves on (a library with users on 1.x, an app in an app store review queue, a game on consoles), you need a place where only fixes go. That place is a release branch.

The model

main:          A---B---C---D---E---F---G
                    \           ↑
release/1.5:         R1--H1    (fix merged/cherry-picked to main too)
                     │    │
                 v1.5.0  v1.5.1
  1. Cut: at feature freeze, branch release/1.5 from main. From now on main gets features for 1.6, and release/1.5 gets only stabilisation fixes.
  2. Stabilise and tag: release candidates (v1.5.0-rc.1, …) and the final v1.5.0 are tagged on the release branch.
  3. Hotfix: a bug in 1.5.0 is fixed with a commit that lands on main first (upstream first) and is cherry-picked to release/1.5, then tagged v1.5.1.
  4. Retire: when 1.5 is out of support, the branch stays (it's history) but gets no more commits. Protect it.

"Upstream first" (fix on main, then pick into the release branch) guarantees the fix can't be forgotten in the next release. The opposite direction (fix on the release branch, merge it back to main) also works, and is what Git Flow does, but it's easy to forget the merge-back.

A session: cut, fix, cherry-pick, tag

bash · try it yourself
git init -q --bare remote.git
git clone -q remote.git app 2>/dev/null && cd app
c() { echo "$2" >> "$1"; git add "$1"; git commit -q -m "$3"; }
c parser.txt "parser" "feat: parser"
c cache.txt "cache" "feat: cache"
git switch -q -c release/1.5
c cache.txt "size fix" "fix: off-by-one in cache size"
git tag -a v1.5.0 -m "1.5.0"
git switch -q main
c ui.txt "dark mode" "feat: dark mode (for 1.6)"
c parser.txt "crash fix" "fix: crash on empty input"
fix=$(git rev-parse HEAD)
git switch -q release/1.5
git cherry-pick -x "$fix" >/dev/null
git tag -a v1.5.1 -m "1.5.1"
git push -q origin main release/1.5 v1.5.0 v1.5.1
echo "--- release/1.5"
git log --format='%h %s%d' release/1.5
echo "--- the picked commit's message"
git log -1 --format=%B release/1.5
echo "--- main"
git log --format='%h %s' main
echo "--- tags containing the original fix: [$(git tag --contains "$fix")]"
echo "--- tags containing the picked fix:   [$(git tag --contains release/1.5)]"
--- release/1.5
d63ac92 fix: crash on empty input (HEAD -> release/1.5, tag: v1.5.1, origin/release/1.5)
ebf9602 fix: off-by-one in cache size (tag: v1.5.0)
a547482 feat: cache
d70c3c4 feat: parser
--- the picked commit's message
fix: crash on empty input

(cherry picked from commit 776fc20cddefd8f058dafb67a981fcc6d472cb2d)

--- main
776fc20 fix: crash on empty input
c9c37cf feat: dark mode (for 1.6)
a547482 feat: cache
d70c3c4 feat: parser
--- tags containing the original fix: []
--- tags containing the picked fix:   [v1.5.1]

Things to notice:

  • cherry-pick -x appends (cherry picked from commit …) to the message. That line is the audit trail: anyone can find the original fix, and tools such as git log --grep find all ports of a fix.
  • The picked commit has a different id from the original: it has a different parent. So git tag --contains <original> doesn't list v1.5.1. Asking "is fix X in release Y?" needs the cherry-pick trailer, or patch-equivalence checks (next lesson).
  • main never received fix: off-by-one in cache size. That fix was made on the release branch during stabilisation; in this model it needs to go to main as well (merge release/1.5 back, or cherry-pick it). The next lesson shows how to find such commits.

Branch naming and protection

Convention Example Notes
release/X.Y release/1.5 one branch per minor line; patch tags on it
release-X.Y.x release-1.5.x same, used by some ecosystems
vX.x / X.x v1.x one branch per major line (common for libraries)
hotfix/… hotfix/crash-empty-input short-lived branch for the fix PR itself (Git Flow)

Protect release branches like main: pull requests required, CI required, no force-push. Release tools need to know about them too; semantic-release, for example, takes maintenance branches as {"name": "1.5.x", "range": "1.5.x"} and refuses to publish a version outside the range (Pre-release Branches & Channels).

Git Flow, GitHub Flow, trunk-based

Model Branches Fits
Trunk-based main + very short feature branches; release from main (tags), feature flags hide unfinished work services deployed continuously; one supported version
GitHub Flow main + feature branches + PRs; deploy from main the same, with review
Release branches on trunk trunk-based + release/X.Y cut per release products with supported older versions (libraries, apps, games)
Git Flow main (released), develop (next), feature/*, release/*, hotfix/* infrequent, scheduled releases; much ceremony, and its author now recommends simpler models for continuously delivered software

The Git Workflow lesson compares these from a developer's point of view, and Branches, Tags & Release Lines shows the game-studio variant with platform certification.

Test yourself

What does "upstream first" mean for a hotfix?

  1. Fix it on the release branch and never on main
  2. Land the fix on main first, then cherry-pick it to the release branch
  3. Push the fix to the upstream fork
  4. Release the fix before reviewing it

Why doesn't git tag --contains <original-fix> list the hotfix release?

  1. Annotated tags hide commits
  2. Cherry-pick creates a new commit with a different id, so the original isn't an ancestor of the tag
  3. The tag wasn't pushed
  4. --contains only works on branches

When do you actually need release branches?

  1. Always
  2. When you must keep supporting a released version while main moves on
  3. Only with Git Flow
  4. Only for libraries