Git Branching
Intro
Choose a branching strategy from the repository's delivery cadence,
supported versions, deployment environments, and release controls. Then
write a small branch contract that makes integration and tagging authority
unambiguous.
Overview
Select a strategy
Answer these questions before naming branches:
- Is
main continuously deployable, or is there a separate release gate?
- Are older versions supported while new major work continues?
- Do environments promote the same commit through test and production?
- Can incomplete work be hidden with feature flags?
- Is the team able to keep shared branches continuously integrated?
Use the smallest model that meets those constraints.
| Strategy |
Best fit |
Long-lived branches |
Release authority |
| Feature Branch Workflow |
Shared integration branch, periodic releases |
integration branch |
integration or release branch |
| GitHub Flow |
Frequent deployment and one supported production line |
main |
main |
| Trunk-Based Development |
Strong CI, feature flags, rapid integration |
main; optional short release branch |
main or just-in-time release branch |
| Gitflow |
Scheduled releases and formal stabilization |
main, develop, temporary release branches |
release branch |
| GitLab Flow |
Environment promotion or maintained stable lines |
main, environment or stable branches |
production or stable branch |
| Version-line integration |
Concurrent major lines or long-lived maintenance |
one dev and release branch per line |
designated line release branch |
Read strategy catalog before choosing a model
with release branches, multiple environments, or concurrent version lines.
Write the branch contract
For each protected long-lived branch, record:
- purpose and allowed changes;
- source branches and merge direction;
- tag authority and release validation command;
- hotfix and backport path;
- required checks, review, force-push, and deletion policy.
Keep task branches short-lived and name them according to git-workflow.
Use merge commits for meaningful integration between long-lived branches;
use the repository's chosen merge method for task branches.
Apply the version-line integration model
Use this model when v0 maintenance and v1 development, or any two supported
major lines, must progress independently:
line.x-dev -> line.x-release -> tag stable release -> main
next.x-dev -> next.x-pre-release -> tag alpha/beta/rc
-> next.x-release -> tag GA -> main
- Create
line.x-release from the latest stable tag and line.x-dev from
that release branch.
- Merge development into the release branch, validate there, and tag only
there. Merge the tagged stable release into
main immediately afterwards.
- For prereleases, merge development into
next.x-pre-release and tag only
on that branch. Create next.x-release only for general availability.
- Hotfix from the latest stable tag, then merge to the release branch, tag,
merge to
main, and merge back to the development branch.
Gotchas
- Treating
main as both active development and release authority.
This makes concurrent version lines indistinguishable. State whether
main is trunk or published history before creating branches.
- Copying Gitflow mechanically. Gitflow's
develop and release branches
add synchronization cost. Choose it only when scheduled stabilization or
parallel release preparation needs that cost.
- Tagging a development branch. A development head may not have passed
integration checks. Tag only the contract's designated release branch.
- Using environment branches as feature integration branches. Environment
branches promote tested commits; they are not a substitute for a developer
integration target unless the contract explicitly says so.
- Forgetting the return path for hotfixes. A production fix that is not
merged back into active development will recur in the next release.
- Protecting a branch without defining how automation merges it. Check
required reviews, checks, merge queue, and allowed merge methods before
making the branch the only release path.
Full reference
Required output
Deliver a branch contract in this form:
Strategy:
Reason for fit:
Protected branches:
Merge directions:
Tag authority:
Hotfix and backport policy:
Required checks and release commands:
Migration steps and rollback point:
Do not migrate a live repository by renaming, deleting, or force-updating
branches until its existing tags, release consumers, and protection rules
have been inspected.
Anti-patterns
- A branch per person or indefinitely open feature branch. Prefer a
focused task branch and merge it promptly.
- A release branch for every routine deployment. If the product can
release directly from a healthy trunk, extra release branches add delay.
- One undocumented catch-all branch. A branch without a stated authority
eventually receives incompatible development, release, and hotfix changes.
Cross-references
- Strategy catalog
git-workflow — naming, commits, pull requests, and merge methods
release-semver — changelog, tags, publishing, and release verification
1---2name: git-branching3description: Select, document, and evolve a Git branching strategy for a repository. Use when comparing Gitflow, GitHub Flow, trunk-based development, feature branches, release branches, or concurrent version lines.4---56# Git Branching78## Intro910Choose a branching strategy from the repository's delivery cadence,11supported versions, deployment environments, and release controls. Then12write a small branch contract that makes integration and tagging authority13unambiguous.1415## Overview1617### Select a strategy1819Answer these questions before naming branches:20211. Is `main` continuously deployable, or is there a separate release gate?222. Are older versions supported while new major work continues?233. Do environments promote the same commit through test and production?244. Can incomplete work be hidden with feature flags?255. Is the team able to keep shared branches continuously integrated?2627Use the smallest model that meets those constraints.2829| Strategy | Best fit | Long-lived branches | Release authority |30| --- | --- | --- | --- |31| Feature Branch Workflow | Shared integration branch, periodic releases | integration branch | integration or release branch |32| GitHub Flow | Frequent deployment and one supported production line | `main` | `main` |33| Trunk-Based Development | Strong CI, feature flags, rapid integration | `main`; optional short release branch | `main` or just-in-time release branch |34| Gitflow | Scheduled releases and formal stabilization | `main`, `develop`, temporary release branches | release branch |35| GitLab Flow | Environment promotion or maintained stable lines | `main`, environment or stable branches | production or stable branch |36| Version-line integration | Concurrent major lines or long-lived maintenance | one dev and release branch per line | designated line release branch |3738Read [strategy catalog](references/strategies.md) before choosing a model39with release branches, multiple environments, or concurrent version lines.4041### Write the branch contract4243For each protected long-lived branch, record:4445- purpose and allowed changes;46- source branches and merge direction;47- tag authority and release validation command;48- hotfix and backport path;49- required checks, review, force-push, and deletion policy.5051Keep task branches short-lived and name them according to `git-workflow`.52Use merge commits for meaningful integration between long-lived branches;53use the repository's chosen merge method for task branches.5455### Apply the version-line integration model5657Use this model when v0 maintenance and v1 development, or any two supported58major lines, must progress independently:5960```text61line.x-dev -> line.x-release -> tag stable release -> main6263next.x-dev -> next.x-pre-release -> tag alpha/beta/rc64 -> next.x-release -> tag GA -> main65```6667- Create `line.x-release` from the latest stable tag and `line.x-dev` from68 that release branch.69- Merge development into the release branch, validate there, and tag only70 there. Merge the tagged stable release into `main` immediately afterwards.71- For prereleases, merge development into `next.x-pre-release` and tag only72 on that branch. Create `next.x-release` only for general availability.73- Hotfix from the latest stable tag, then merge to the release branch, tag,74 merge to `main`, and merge back to the development branch.7576## Gotchas7778- **Treating `main` as both active development and release authority.**79 This makes concurrent version lines indistinguishable. State whether80 `main` is trunk or published history before creating branches.81- **Copying Gitflow mechanically.** Gitflow's `develop` and release branches82 add synchronization cost. Choose it only when scheduled stabilization or83 parallel release preparation needs that cost.84- **Tagging a development branch.** A development head may not have passed85 integration checks. Tag only the contract's designated release branch.86- **Using environment branches as feature integration branches.** Environment87 branches promote tested commits; they are not a substitute for a developer88 integration target unless the contract explicitly says so.89- **Forgetting the return path for hotfixes.** A production fix that is not90 merged back into active development will recur in the next release.91- **Protecting a branch without defining how automation merges it.** Check92 required reviews, checks, merge queue, and allowed merge methods before93 making the branch the only release path.9495## Full reference9697### Required output9899Deliver a branch contract in this form:100101```text102Strategy:103Reason for fit:104Protected branches:105Merge directions:106Tag authority:107Hotfix and backport policy:108Required checks and release commands:109Migration steps and rollback point:110```111112Do not migrate a live repository by renaming, deleting, or force-updating113branches until its existing tags, release consumers, and protection rules114have been inspected.115116### Anti-patterns117118- **A branch per person or indefinitely open feature branch.** Prefer a119 focused task branch and merge it promptly.120- **A release branch for every routine deployment.** If the product can121 release directly from a healthy trunk, extra release branches add delay.122- **One undocumented catch-all branch.** A branch without a stated authority123 eventually receives incompatible development, release, and hotfix changes.124125### Cross-references126127- [Strategy catalog](references/strategies.md)128- `git-workflow` — naming, commits, pull requests, and merge methods129- `release-semver` — changelog, tags, publishing, and release verification