From Beginner to Advanced: A Complete One-Stop Guide for Designing Branching Strategies
1. What is a source control branching model?
A source control branching model is the agreed structure and rule system for creating, using, merging, releasing, and deleting branches in a source control repository.
It defines:
- Which branch represents production.
- Where developers create new work.
- How long branches live.
- How code moves between branches.
- When release branches are created.
- How hotfixes are handled.
- How environments map to source control.
- Who can merge into important branches.
- What automation must pass before merge.
- How to keep the repository clean, safe, and releasable.
Simple definition:
A branching model is the traffic system for source code.
Without it, everyone drives wherever they want. With it, teams know exactly where changes enter, where they are reviewed, where they are released, and how production is protected.
2. Branching model vs Git workflow vs version control workflow
These terms are related, but not identical.
| Term | Meaning | Example |
|---|---|---|
| Version control system | Tool used to track changes | Git, SVN, Mercurial, Perforce |
| Source control workflow | Full process from change to release | Branch โ PR โ CI โ merge โ deploy |
| Branching model | Branch structure and merge rules | Gitflow, trunk-based, GitHub Flow |
| Release model | How code becomes a version or deployment | Tags, release branches, GitOps promotion |
| Review model | How changes are approved | PR, MR, changelist, CODEOWNERS |
| Deployment model | How code reaches environments | CI/CD, GitOps, manual promotion |
A branching model is one major part of the wider source control workflow.
3. Why branching models exist
A repository is not just a folder of code. It is a collaboration system.
Branching models solve these problems:
- Multiple developers working at the same time.
- Features taking different amounts of time.
- Production needing stability.
- Bugs needing emergency fixes.
- Releases needing version control.
- Some work needing review before merge.
- Some changes being too risky to ship immediately.
- Older versions needing support.
- CI/CD needing a predictable source of truth.
Gitโs official documentation describes branches as a normal part of real-world workflows, including creating branches for work, switching to a hotfix when needed, and merging changes back.
4. The branch is not the goal
A beginner asks:
Which branch should I create?
A senior engineer asks:
What risk am I isolating?
An architect asks:
What delivery system are we designing?
Branches are not decoration. Every branch should have a reason.
flowchart TD
A[Need to isolate work?] --> B[Create branch]
B --> C[Review branch purpose]
C --> D{Does this branch protect speed, quality, release, or production?}
D -- Yes --> E[Valid branch]
D -- No --> F[Unnecessary complexity]
Code language: JavaScript (javascript)
5. The five core purposes of branches
Every branch usually exists for one of five reasons.
| Branch purpose | What it protects | Example branch |
|---|---|---|
| Development isolation | Unfinished work | feature/add-login |
| Integration | Shared team work | main, develop |
| Release stabilization | Version quality | release/2.1.0 |
| Production repair | Emergency fixes | hotfix/payment-crash |
| Environment promotion | Deployment stages | staging, production |
If a branch does not serve one of these purposes, question whether it should exist.
6. Core branch types
6.1 Main branch
The main branch is the primary integration line.
Common names:
main
master
trunk
mainline
Modern teams usually use main.
In trunk-based development, the primary branch is commonly called trunk, main, or mainline, and developers integrate frequently into it while avoiding long-running development branches.
6.2 Feature branch
A feature branch isolates new work.
feature/add-user-login
feature/device-search
feature/report-export
Code language: JavaScript (javascript)
Feature branches should be short-lived. The longer they live, the higher the merge risk.
flowchart LR
A[main] --> B[feature branch]
B --> C[Pull request]
C --> D[Review + CI]
D --> E[Merge to main]
E --> F[Delete branch]
Code language: CSS (css)
6.3 Bugfix branch
A bugfix branch fixes a normal defect that is not an emergency production incident.
bugfix/login-timeout
bugfix/wrong-invoice-total
bugfix/api-null-response
Code language: JavaScript (javascript)
6.4 Hotfix branch
A hotfix branch fixes a production issue urgently.
hotfix/payment-crash
hotfix/prod-login-failure
hotfix/security-token-leak
Hotfix branches should be:
- short-lived
- minimal
- reviewed quickly
- tested with critical checks
- merged back into all relevant active branches
- tagged if they create a production release
6.5 Release branch
A release branch stabilizes a version before it is shipped.
release/1.5.0
release/2026.07
release/mobile-4.2.0
Release branches are useful when:
- QA needs time.
- Production release is scheduled.
- App store approval exists.
- Enterprise customers require versioned packages.
- You support multiple versions.
- Not every merged change should ship immediately.
AWS Prescriptive Guidance describes Gitflow as a model that works well for scheduled release cycles where features are collected into a release and moved through development, release, and production branches.
6.6 Support branch
A support branch maintains an older version.
support/1.0
support/2.4-lts
maintenance/2025-lts
Use support branches when customers cannot upgrade immediately or when you maintain long-term support versions.
6.7 Experiment branch
An experiment branch is for temporary exploration.
experiment/new-cache-engine
spike/oauth-provider-test
prototype/new-dashboard
Code language: JavaScript (javascript)
Experiment branches must have an expiry. Otherwise, they become branch graveyards.
6.8 Environment branch
Environment branches map branches to deployment environments.
dev
staging
production
GitLab documents branch-per-environment as one possible branching strategy, alongside web-service and long-lived release-branch models.
Environment branches can work, but they can also become messy if teams randomly merge between them without strict promotion rules.
7. Branch lifespan: the most important hidden factor
The biggest branching model mistake is not choosing Gitflow or trunk-based development.
The biggest mistake is letting branches live too long.
xychart-beta
title "Branch lifetime vs integration risk"
x-axis ["Hours", "1 day", "3 days", "1 week", "2 weeks", "1 month"]
y-axis "Risk" 0 --> 100
bar [5, 10, 20, 40, 70, 95]
Code language: JavaScript (javascript)
This is a conceptual risk model. The practical lesson is simple:
Long-lived branches delay integration pain. They do not remove it.
8. The golden branching rule
The more frequently you integrate, the less painful integration becomes.
Trunk-based development strongly emphasizes short-lived branches or direct-to-trunk commits, with feature branches coming back quickly as pull requests into trunk/main.
9. Branching model maturity levels
flowchart TD
L1[Level 1: No model] --> L2[Level 2: Main branch only]
L2 --> L3[Level 3: Feature branches]
L3 --> L4[Level 4: Pull requests]
L4 --> L5[Level 5: Protected main]
L5 --> L6[Level 6: CI gates]
L6 --> L7[Level 7: Release / hotfix branches]
L7 --> L8[Level 8: Feature flags]
L8 --> L9[Level 9: Trunk-based or GitOps maturity]
L9 --> L10[Level 10: Enterprise branch governance]
Code language: CSS (css)
| Level | Behavior | Risk |
|---|---|---|
| 1 | No branch rules | Extreme |
| 2 | Everyone pushes to main | High |
| 3 | Feature branches exist | Medium-high |
| 4 | Pull requests required | Medium |
| 5 | Main branch protected | Lower |
| 6 | CI required | Low |
| 7 | Release/hotfix process exists | Lower |
| 8 | Feature flags reduce release risk | Low |
| 9 | Frequent integration and automated deploy | Very low |
| 10 | Audited, governed, measurable | Enterprise-grade |
GitHub branch protection rules can enforce workflows such as required approvals and passing status checks before pull requests merge into protected branches.
10. The major source control branching models
The common models are:
- Mainline model
- Feature branch model
- GitHub Flow
- GitLab Flow
- Gitflow
- Trunk-based development
- Release branch model
- Environment branch model
- Fork-based model
- GitOps branching model
- Monorepo branching model
- Support/LTS branching model
mindmap
root((Branching Models))
Mainline
Feature Branch
GitHub Flow
GitLab Flow
Gitflow
Trunk Based
Release Branch
Environment Branch
Fork Based
GitOps
Monorepo
Support LTS
11. Model 1: Mainline branching model
What it is
The mainline model uses one primary branch.
main
gitGraph
commit id: "A"
commit id: "B"
commit id: "C"
commit id: "D"
Code language: JavaScript (javascript)
How it works
Developers commit directly to main, or very small branches are merged quickly.
Best for
- Solo projects
- Tiny teams
- Prototypes
- Learning repositories
- Internal scripts
Bad for
- Large teams
- Production-critical systems
- Regulated environments
- Slow CI
- Weak review culture
Rules if you use it
mainmust always build.- Pull before work.
- Push small commits.
- Use CI.
- Use tags for important versions.
- Avoid direct production deploys without validation.
Verdict
Mainline is simple, but without protection it becomes dangerous quickly.
12. Model 2: Feature branch model
What it is
Each feature, bug, or task gets a temporary branch.
gitGraph
commit id: "main-1"
branch feature/login
checkout feature/login
commit id: "login-1"
commit id: "login-2"
checkout main
branch bugfix/payment-timeout
checkout bugfix/payment-timeout
commit id: "fix-1"
checkout main
merge feature/login
merge bugfix/payment-timeout
Code language: JavaScript (javascript)
Branches
main
feature/*
bugfix/*
hotfix/*
Process
flowchart TD
A[Start from main] --> B[Create feature branch]
B --> C[Commit changes]
C --> D[Push branch]
D --> E[Open PR / MR]
E --> F[CI checks]
E --> G[Code review]
F --> H{Pass?}
G --> I{Approved?}
H -- No --> C
I -- No --> C
H -- Yes --> J[Merge to main]
I -- Yes --> J
J --> K[Delete branch]
Code language: JavaScript (javascript)
Best for
- Most modern software teams
- Backend services
- Frontend apps
- DevOps repositories
- Infrastructure as Code
- Teams still maturing toward trunk-based development
Benefits
- Easy to understand.
- Isolates work.
- Supports pull requests.
- Keeps
mainprotected. - Works well with CI/CD.
Risks
- Feature branches can become long-lived.
- Big branches create painful conflicts.
- Developers may delay integration.
- Reviews become too large.
Policy
Feature branches should live for hours or days, not weeks.
13. Model 3: GitHub Flow
What it is
GitHub Flow is a lightweight branch-based workflow: create a branch, make commits, open a pull request, review, merge, and deploy. GitHubโs own documentation describes GitHub Flow as a lightweight branch-based workflow.
flowchart LR
A[Create branch from main] --> B[Commit changes]
B --> C[Open pull request]
C --> D[Discuss and review]
D --> E[CI checks]
E --> F[Merge to main]
F --> G[Deploy]
Code language: CSS (css)
Branches
main
feature/*
bugfix/*
hotfix/*
Philosophy
main is always deployable.
Best for
- Web apps
- SaaS
- APIs
- Documentation repos
- Internal tools
- Teams that deploy frequently
Not ideal for
- Mobile apps with store approval
- Desktop software
- Firmware
- Products with long QA cycles
- Teams supporting many old versions
Example branch policy
| Branch | Rule |
|---|---|
main | Protected, always deployable |
feature/* | Short-lived, PR required |
hotfix/* | Emergency production fix |
release/* | Optional, only if needed |
14. Model 4: GitLab Flow
What it is
GitLab Flow combines feature branches and merge requests with issue tracking, production branches, environment branches, or release branches. GitLab describes GitLab Flow as a simpler alternative to Gitflow that combines feature-driven development and feature branches with issue tracking while allowing production and stable branches.
flowchart TD
A[Feature branch] --> B[Merge request]
B --> C[main]
C --> D[staging]
D --> E[production]
Code language: CSS (css)
Common GitLab Flow patterns
Pattern A: Main + production branch
main
production
Pattern B: Main + environment branches
main
staging
production
Pattern C: Main + release branches
main
release/1.0
release/1.1
release/2.0
GitLabโs branching strategy documentation says branching and code-management strategies depend on product needs and lists major categories such as web services, long-lived release branches, and branch-per-environment models.
Best for
- Teams using GitLab
- Teams needing environment promotion
- Teams that want more structure than GitHub Flow
- Enterprise web services
- Projects with production/stable branches
Strength
GitLab Flow sits nicely between lightweight GitHub Flow and heavier Gitflow.
15. Model 5: Gitflow
What it is
Gitflow is a structured branching model with multiple long-lived branches and supporting short-lived branches.
Typical branches:
main
develop
feature/*
release/*
hotfix/*
Atlassian describes Gitflow as a branching model that uses feature branches and multiple primary branches; it is more branch-heavy than trunk-based development.
gitGraph
commit id: "prod-1"
branch develop
checkout develop
commit id: "dev-1"
branch feature/login
checkout feature/login
commit id: "login-work"
checkout develop
merge feature/login
branch release/1.1.0
checkout release/1.1.0
commit id: "release-fix"
checkout main
merge release/1.1.0 tag: "v1.1.0"
checkout develop
merge release/1.1.0
checkout main
branch hotfix/1.1.1
checkout hotfix/1.1.1
commit id: "hotfix"
checkout main
merge hotfix/1.1.1 tag: "v1.1.1"
checkout develop
merge hotfix/1.1.1
Code language: JavaScript (javascript)
Branch roles
| Branch | Purpose |
|---|---|
main | Production-ready code |
develop | Integration branch for next release |
feature/* | New feature work |
release/* | Stabilization before release |
hotfix/* | Emergency production fix |
support/* | Optional older-version maintenance |
Gitflow lifecycle
flowchart TD
A[feature branch] --> B[develop]
B --> C[release branch]
C --> D[main]
D --> E[tag version]
D --> F[hotfix branch]
F --> D
F --> B
Code language: CSS (css)
Best for
- Versioned software
- Mobile apps
- Desktop apps
- Firmware
- SDKs
- On-prem software
- Products with scheduled release trains
- Teams that need formal stabilization
Weaknesses
- More branches to manage.
developcan become unstable.- Long-lived branches increase conflict risk.
- Slower than trunk-based development.
- Overkill for many web services.
Practical rule
Use Gitflow only when release management complexity is real.
Do not use Gitflow just because it sounds professional.
16. Model 6: Trunk-based development
What it is
Trunk-based development is a branching model where developers integrate small changes into a single shared trunk/main branch frequently. The trunk-based development reference site argues against long-running branches and supports direct-to-trunk or short-lived pull-request branches.
gitGraph
commit id: "A"
branch tiny-change-1
checkout tiny-change-1
commit id: "B"
checkout main
merge tiny-change-1
branch tiny-change-2
checkout tiny-change-2
commit id: "C"
checkout main
merge tiny-change-2
commit id: "D"
Code language: JavaScript (javascript)
Branches
main
short-lived/*
Some very mature teams may commit directly to trunk, but many modern teams still use short-lived PR branches.
Key rule
Branches are temporary. Trunk is the center of gravity.
Best for
- SaaS
- APIs
- high-performing teams
- monorepos
- platform teams
- teams with strong CI/CD
- teams using feature flags
- teams doing continuous delivery
Required practices
- Small changes
- Fast CI
- Strong automated tests
- Feature flags
- Quick code review
- Easy rollback
- Main branch always healthy
Feature flags are critical
Feature flags separate merge from release.
flowchart LR
A[Code merged to main] --> B[Feature flag OFF]
B --> C[Deploy safely]
C --> D[Enable internally]
D --> E[Enable 10%]
E --> F[Enable 100%]
Code language: CSS (css)
Trunk-based warning
Trunk-based development is not โeveryone randomly pushes to main.โ
Real trunk-based development is disciplined, automated, and tested.
17. Model 7: Release branch model
What it is
The release branch model creates a branch for each release line.
main
release/1.0
release/1.1
release/2.0
gitGraph
commit id: "A"
commit id: "B"
branch release/2.0
checkout release/2.0
commit id: "rc-fix-1"
commit id: "rc-fix-2"
checkout main
commit id: "future-work"
checkout release/2.0
commit id: "release-ready" tag: "v2.0.0"
Code language: JavaScript (javascript)
Best for
- QA stabilization
- release candidates
- certification cycles
- mobile releases
- enterprise product releases
- long-lived customer versions
Rules
Allowed on release branch:
- bug fixes
- release notes
- version bumps
- stabilization changes
- documentation corrections
Not allowed:
- new features
- major refactors
- risky dependency upgrades
- unrelated cleanup
- experimental changes
18. Model 8: Environment branch model
What it is
Each branch represents an environment.
dev
staging
production
flowchart LR
A[main/dev] --> B[staging]
B --> C[production]
Code language: CSS (css)
Best for
- simple branch-triggered deployments
- GitLab-style environment promotion
- small teams with strict promotion discipline
Common problem
Environment branches drift.
Example:
staging has changes that production does not have
production has hotfixes that staging does not have
main has future work that neither has
This becomes confusing quickly.
Better modern alternative
Use:
main branch + environment folders + promotion pipeline
Example:
environments/
dev/
staging/
production/
19. Model 9: Fork-based branching model
What it is
External contributors fork the repository, work in their own fork, and submit pull requests back to the upstream repository.
flowchart LR
A[Upstream repository] --> B[Contributor fork]
B --> C[Contributor branch]
C --> D[Pull request]
D --> E[Maintainer review]
E --> F[Merge upstream]
Code language: CSS (css)
Best for
- open-source projects
- external contributors
- public repositories
- vendor contributions
- cases where contributors should not have write access
Common branch structure
Contributor fork:
main
feature/fix-readme
bugfix/api-timeout
Upstream repository:
main
release/*
20. Model 10: GitOps branching model
What it is
GitOps uses Git as the desired state of infrastructure or deployment configuration.
flowchart LR
A[Application repo] --> B[Build image]
B --> C[Update GitOps repo]
C --> D[Argo CD / Flux]
D --> E[Kubernetes cluster]
Code language: CSS (css)
Common GitOps structures
Option A: Directory per environment
clusters/
dev/
staging/
production/
Option B: Branch per environment
env/dev
env/staging
env/production
Option C: Directory per cluster
clusters/
ap-northeast-1-dev/
ap-northeast-1-prod/
Best practice
For most teams:
Use one main branch and folders per environment.
Code language: PHP (php)
This avoids messy environment branch drift.
21. Model 11: Monorepo branching model
What it is
A monorepo stores many projects in one repository.
repo/
apps/
web/
admin/
services/
auth/
payment/
notification/
packages/
common/
ui/
infra/
docs/
Recommended model
For monorepos, trunk-based development often works best.
main
short-lived feature branches
CODEOWNERS
path-based CI
feature flags
Why?
Long-lived branches in monorepos become painful because many teams modify the same repository.
flowchart TD
A[Monorepo change] --> B[Detect changed paths]
B --> C[Run affected tests]
C --> D[Request CODEOWNERS review]
D --> E[Merge to main]
E --> F[Build affected artifacts only]
Code language: CSS (css)
Monorepo branch rules
| Rule | Reason |
|---|---|
| Keep branches short-lived | Avoid conflicts across teams |
| Use path-based CI | Avoid running everything |
| Use CODEOWNERS | Require right reviewers |
| Use feature flags | Hide incomplete work |
| Avoid release branches unless necessary | Release branches become complex in monorepos |
22. Model 12: Support/LTS branching model
What it is
Support branches maintain older versions.
main
release/3.0
support/2.5-lts
support/1.9-lts
flowchart LR
A[main] --> B[release/3.0]
A --> C[support/2.5-lts]
A --> D[support/1.9-lts]
E[Security fix] --> B
E --> C
E --> D
Code language: CSS (css)
Best for
- enterprise software
- libraries
- SDKs
- operating systems
- firmware
- products with long customer upgrade cycles
Backporting
A bug fix may need to be applied to multiple active support branches.
flowchart LR
A[Fix in main] --> B[Cherry-pick to release/3.0]
A --> C[Cherry-pick to support/2.5-lts]
B --> D[Tag v3.0.4]
C --> E[Tag v2.5.12]
Code language: CSS (css)
23. Branching model comparison table
| Model | Branch count | Speed | Governance | Complexity | Best for |
|---|---|---|---|---|---|
| Mainline | Low | High | Low | Low | Solo/tiny teams |
| Feature branch | Medium | Medium-high | Medium | Medium | Most teams |
| GitHub Flow | Low-medium | High | Medium | Low-medium | Web/SaaS |
| GitLab Flow | Medium | Medium | High | Medium | Env promotion |
| Gitflow | High | Medium | High | High | Versioned releases |
| Trunk-based | Low | Very high | High if automated | Medium-high | Mature CI/CD |
| Release branch | Medium | Medium | High | Medium | QA/release windows |
| Environment branch | Medium | Low-medium | Medium | Medium-high | Simple branch deploys |
| Fork-based | Medium | Medium | High | Medium | Open source |
| GitOps | Medium | High | High | Medium | Kubernetes/platform |
| Monorepo trunk | Low | Very high | High | High tooling needed | Large repos |
| Support/LTS | High | Low-medium | Very high | High | Older versions |
24. How to choose the right branching model
flowchart TD
A[Choose branching model] --> B{External contributors?}
B -- Yes --> C[Fork-based model]
B -- No --> D{Deploy many times per week?}
D -- Yes --> E{Strong CI + tests + feature flags?}
E -- Yes --> F[Trunk-based development]
E -- No --> G[GitHub Flow / Feature branch model]
D -- No --> H{Scheduled versioned releases?}
H -- Yes --> I{Need develop + release + hotfix structure?}
I -- Yes --> J[Gitflow]
I -- No --> K[Release branch model]
H -- No --> L{Need environment promotion?}
L -- Yes --> M[GitLab Flow or GitOps folders]
L -- No --> N[Feature branch model]
25. Branching model by project type
| Project type | Recommended model |
|---|---|
| Solo learning project | Mainline |
| Small internal tool | GitHub Flow |
| SaaS backend | Trunk-based or GitHub Flow |
| Enterprise web app | GitLab Flow |
| Mobile app | Gitflow or release branches |
| Desktop app | Gitflow |
| Firmware | Gitflow + support branches |
| SDK/library | Release branches + SemVer |
| Terraform IaC | Feature branch + protected main |
| Kubernetes GitOps | Main + environment folders |
| Open source | Fork-based model |
| Monorepo | Trunk-based + CODEOWNERS |
| Regulated system | Release branches + approvals |
| Game development | Stream/lock model or Perforce-style |
| Long-term enterprise product | Support/LTS branches |
26. The source control branching design framework
Before selecting a branching model, ask these questions.
26.1 Release cadence
| Question | Impact |
|---|---|
| Do we release daily? | Prefer trunk-based/GitHub Flow |
| Do we release weekly/monthly? | Feature branch or GitLab Flow |
| Do we release quarterly? | Release branches/Gitflow |
| Do customers run old versions? | Support branches |
26.2 Deployment model
| Question | Impact |
|---|---|
| Is every merge deployable? | Trunk-based/GitHub Flow |
| Do we promote through environments? | GitLab Flow/GitOps |
| Are releases manual? | Release branches |
| Is deployment separate from release? | Feature flags |
26.3 Team size
| Team size | Recommended model |
|---|---|
| 1โ3 engineers | Mainline/GitHub Flow |
| 4โ20 engineers | Feature branch/GitHub Flow |
| 20โ100 engineers | Trunk-based/GitLab Flow |
| 100+ engineers | Trunk-based, monorepo, CODEOWNERS, automation |
26.4 Risk level
| Risk level | Branching style |
|---|---|
| Low risk | Lightweight branches |
| Medium risk | PR + CI + protected main |
| High risk | Release branches + approvals |
| Critical/regulatory | Audited branches + change control |
27. The best default branching model for most teams
For most modern teams, use this:
main
feature/*
bugfix/*
hotfix/*
release/* only when needed
Rules
mainis always healthy.- No direct push to
main. - All changes go through PR/MR.
- CI must pass before merge.
- At least one review required.
- Feature branches must be short-lived.
- Hotfix branches start from production state.
- Release branches are created only when stabilization is needed.
- Branches are deleted after merge.
- Every production release is tagged.
GitHub protected branches can prevent deletion or force pushing and can require status checks or linear history before changes land.
28. Branch naming standard
Recommended format
<type>/<ticket-id>-<short-description>
Code language: HTML, XML (xml)
Examples
feature/EVP-123-add-device-search
bugfix/EVP-224-fix-login-timeout
hotfix/EVP-911-fix-prod-crash
release/2.4.0
support/1.9-lts
docs/EVP-410-update-runbook
chore/EVP-301-upgrade-dependencies
security/EVP-777-rotate-token
experiment/new-cache-design
Code language: JavaScript (javascript)
Branch type guide
| Prefix | Purpose |
|---|---|
feature/ | New capability |
bugfix/ | Normal defect fix |
hotfix/ | Emergency production fix |
release/ | Release stabilization |
support/ | Older version maintenance |
docs/ | Documentation |
chore/ | Maintenance |
refactor/ | Internal restructuring |
security/ | Security fix |
experiment/ | Temporary exploration |
test/ | Test-only changes |
29. Branch protection model
Important branches need protection.
Recommended protection rules
| Branch | Protection |
|---|---|
main | Strongest protection |
release/* | Strong protection |
hotfix/* | Fast review, critical CI |
develop | Protected if used |
production | Very strong protection |
staging | Protected if environment branch |
feature/* | Usually no strict protection |
Main branch protection
- No direct push
- Pull request required
- Required status checks
- Required approval
- CODEOWNERS review for critical paths
- No force push
- No branch deletion
- Signed commits if required
Branch protection and required status checks are platform-level enforcement mechanisms, not just team wishes. GitHub documents that required status checks can block merging until checks pass.
30. Merge model
A branching model is incomplete without a merge model.
Common merge strategies
| Strategy | Meaning | Best for |
|---|---|---|
| Merge commit | Preserve branch history | Audit-heavy teams |
| Squash merge | One PR becomes one commit | Clean main history |
| Rebase merge | Linear history | Teams with strong Git discipline |
| Fast-forward | Move pointer forward only | Trunk/mainline workflows |
Recommended default
Use squash merge for normal feature branches.
Use merge commits for release/hotfix branches when audit trail matters.
Use rebase locally to clean up your own branch.
Code language: PHP (php)
Gitโs documentation describes git merge as the command used to merge one or more branches into the branch currently checked out.
31. Branch lifecycle
Every branch should have a birth, purpose, and death.
flowchart TD
A[Create branch] --> B[Work]
B --> C[Push]
C --> D[Open PR/MR]
D --> E[Review + CI]
E --> F[Merge]
F --> G[Delete branch]
Code language: CSS (css)
Healthy branch lifecycle
| Stage | Good behavior |
|---|---|
| Create | From latest correct base |
| Work | Small commits |
| Update | Rebase/merge from base regularly |
| Review | Small PR/MR |
| Merge | After approval and CI |
| Delete | Immediately after merge |
Unhealthy branch lifecycle
create branch โ work for 3 months โ massive conflict โ panic merge โ production bug
32. Branch age policy
| Branch type | Ideal lifetime | Maximum recommended lifetime |
|---|---|---|
| Feature branch | Hoursโ3 days | 1 week |
| Bugfix branch | Hoursโ2 days | 1 week |
| Hotfix branch | Minutesโhours | 1 day |
| Release branch | Daysโweeks | Release-dependent |
| Support branch | Monthsโyears | Product-dependent |
| Experiment branch | Days | 1โ2 weeks |
| Environment branch | Long-lived | Must be strictly governed |
33. Release branch model in detail
A release branch is created when a release needs stabilization.
flowchart TD
A[main/develop] --> B[Create release/2.5.0]
B --> C[QA testing]
C --> D[Bug fixes only]
D --> E[Release candidate]
E --> F[Tag v2.5.0]
F --> G[Deploy/ship production]
Code language: CSS (css)
Release branch rules
Allowed:
fix
docs
version bump
release notes
configuration correction
safe test update
Not allowed:
new feature
large refactor
experimental dependency
unrelated cleanup
database-breaking change without plan
Code language: JavaScript (javascript)
Release branch naming
release/2.5.0
release/2026.07
release/mobile-4.1.0
release/api-v3
34. Hotfix branch model in detail
Hotfix branches fix production.
flowchart TD
A[Production incident] --> B[Find production commit/tag]
B --> C[Create hotfix branch]
C --> D[Minimal fix]
D --> E[Emergency PR]
E --> F[Critical CI]
F --> G[Merge]
G --> H[Deploy]
H --> I[Tag patch release]
I --> J[Merge/backport to active branches]
Code language: CSS (css)
Hotfix rules
- Start from production branch/tag.
- Fix only the incident.
- Avoid refactoring.
- Avoid unrelated changes.
- Keep review short but real.
- Deploy quickly.
- Back-merge or cherry-pick to main/develop/release as needed.
- Write follow-up cleanup ticket.
Hotfix naming
hotfix/2.5.1-payment-crash
hotfix/prod-login-timeout
hotfix/CVE-2026-1234
35. Support branch model in detail
Support branches exist when older versions are maintained.
gitGraph
commit id: "v1 base"
branch support/1.x
checkout support/1.x
commit id: "1.x fix"
checkout main
commit id: "v2 work"
branch support/2.x
checkout support/2.x
commit id: "2.x fix"
Code language: JavaScript (javascript)
Backport policy
When a bug is fixed in main, decide whether it should be backported.
| Question | Backport? |
|---|---|
| Security vulnerability? | Yes |
| Data corruption? | Yes |
| Production crash? | Usually yes |
| Minor UI bug? | Maybe |
| New feature? | Usually no |
| Refactor? | No |
36. Environment branch model in detail
Environment branches can look simple:
dev โ staging โ production
But the danger is branch drift.
flowchart TD
A[main] --> B[staging]
A --> C[production]
B --> D[staging-only fix]
C --> E[production-only hotfix]
D --> F[Drift]
E --> F
Code language: CSS (css)
Safe environment branch rules
If you use environment branches:
- Promotion direction must be clear.
- Never make random direct changes in higher environments.
- Hotfixes must flow back to lower branches.
- CI must validate every promotion.
- Branch differences must be visible.
- Staging and production should not become independent products.
Better GitOps style
main
clusters/dev
clusters/staging
clusters/prod
Same branch, separate environment folders.
37. GitOps source branching design
For Kubernetes and platform teams, this is often the cleanest model.
flowchart TD
A[App source repo] --> B[Build image]
B --> C[Image tag: sha-abc123]
C --> D[GitOps repo PR]
D --> E[Update dev folder]
E --> F[Promote same image to staging]
F --> G[Promote same image to production]
G --> H[Argo CD / Flux sync]
Code language: CSS (css)
Repository layout
gitops-repo/
apps/
auth/
payment/
notification/
environments/
dev/
staging/
production/
clusters/
dev-apne1/
prod-apne1/
Golden rule
Build once. Promote the same artifact.
Do not rebuild different images for dev, staging, and production.
38. Branching and Semantic Versioning
Branching and versioning are connected.
Semantic Versioning defines MAJOR.MINOR.PATCH, where major is for incompatible API changes, minor is for backward-compatible functionality, and patch is for backward-compatible bug fixes.
v1.0.0
v1.1.0
v1.1.1
v2.0.0
Code language: CSS (css)
Branch to version mapping
| Branch | Version behavior |
|---|---|
main | Next version / production-ready |
release/1.4.0 | Stabilizing v1.4.0 |
hotfix/1.4.1 | Patch release |
support/1.x | Older major version |
feature/* | No version until merged |
Example
release/2.3.0 โ tag v2.3.0
hotfix/2.3.1-payment โ tag v2.3.1
support/1.9-lts โ tag v1.9.12
39. Branching and CI/CD
Branching models only work when CI/CD understands branch meaning.
flowchart TD
A[Branch pushed] --> B{Branch type?}
B -- feature/* --> C[Run tests + lint + build]
B -- main --> D[Run full CI + deploy staging]
B -- release/* --> E[Run release validation]
B -- hotfix/* --> F[Run critical tests]
B -- production --> G[Deploy production]
Recommended branch pipeline behavior
| Branch | CI behavior |
|---|---|
feature/* | Lint, unit test, build |
bugfix/* | Lint, unit test, build |
main | Full CI, integration tests, deploy to dev/staging |
release/* | Full release validation |
hotfix/* | Critical tests, security checks |
production | Production deployment only |
support/* | Version-specific tests |
40. Branching and code review
Every branching model needs review rules.
Review rules by branch type
| Branch target | Review rule |
|---|---|
main | At least 1 approval |
release/* | Release owner approval |
hotfix/* | Emergency reviewer approval |
production | Production owner approval |
support/* | Maintainer approval |
| Infrastructure paths | Platform/DevOps owner |
| Security paths | Security owner |
| Database migrations | Backend + platform/DB owner |
CODEOWNERS example
/infra/ @platform-team
/.github/workflows/ @devops-team
/services/payment/ @payment-team
/services/auth/ @identity-team
/security/ @security-team
/database/migrations/ @backend-leads
41. Branching and database migrations
Database changes often determine whether a branch model succeeds.
Bad branching behavior
feature branch changes schema for 3 weeks
main changes app logic meanwhile
release branch needs old schema
production hotfix now conflicts
Safe model
Use expand-migrate-contract.
flowchart LR
A[Expand schema] --> B[Deploy backward-compatible app]
B --> C[Backfill data]
C --> D[Switch reads/writes]
D --> E[Contract old schema]
Code language: CSS (css)
Branching rule
Database migrations should be:
- small
- backward compatible
- reviewed carefully
- deployed in phases
- not hidden in huge feature branches
42. Branching and feature flags
Feature flags reduce branch complexity.
Without flags:
Feature not ready โ keep branch open
With flags:
Feature not ready โ merge safely behind flag
flowchart TD
A[Create small branch] --> B[Add hidden feature code]
B --> C[Merge to main]
C --> D[Deploy with flag off]
D --> E[Gradually enable]
E --> F[Remove flag after rollout]
Code language: CSS (css)
Best practice
A feature flag lets the team use short-lived branches even for large features.
43. Branching and rollback
Each branching model must define rollback.
flowchart TD
A[Production problem] --> B{Feature flag?}
B -- Yes --> C[Disable flag]
B -- No --> D{Bad deployment?}
D -- Yes --> E[Redeploy previous artifact]
D -- No --> F{Bad commit?}
F -- Yes --> G[Revert commit]
F -- No --> H[Hotfix branch]
Rollback methods
| Problem | Best action |
|---|---|
| Bad feature | Disable flag |
| Bad commit | Revert |
| Bad deployment | Redeploy previous artifact |
| Bad release branch fix | Patch release |
| Bad database migration | Fix forward or planned rollback |
| Security issue | Hotfix + rotate credentials |
44. Branching model for Infrastructure as Code
Infrastructure repositories need a stricter model than app repos.
Recommended IaC branches
main
feature/*
bugfix/*
hotfix/*
Usually avoid long-lived environment branches unless you have a very clear reason.
IaC workflow
flowchart TD
A[Create branch] --> B[Edit Terraform]
B --> C[terraform fmt]
C --> D[terraform validate]
D --> E[Open PR]
E --> F[Terraform plan]
F --> G[Security scan]
G --> H[Cost/blast-radius review]
H --> I[Approval]
I --> J[Merge]
J --> K[Apply via pipeline]
Code language: CSS (css)
IaC branch rules
| Rule | Why |
|---|---|
| No direct push to main | Prevent accidental infra change |
| Plan required on PR | Review actual resource impact |
| Separate prod approval | Reduce production risk |
| No huge infra PRs | Easier blast-radius review |
| No secrets in repo | State/security risk |
| Protect pipeline files | CI/CD controls infrastructure |
45. Branching model for application repositories
Recommended app model
main
feature/*
bugfix/*
hotfix/*
release/* when needed
App branch flow
flowchart TD
A[feature/*] --> B[PR]
B --> C[CI]
C --> D[Review]
D --> E[main]
E --> F[Build artifact]
F --> G[Deploy dev/staging]
G --> H[Deploy production]
Code language: CSS (css)
App-specific rules
- Use feature flags.
- Keep branches short-lived.
- Merge only with green CI.
- Use release tags.
- Make rollback easy.
- Avoid mixing refactor and behavior changes.
46. Branching model for microservices
Microservices often work best with lightweight branching.
Option A: Repository per service
service-auth/
service-payment/
service-notification/
Each service can use:
main
feature/*
hotfix/*
release/*
Option B: Monorepo
services/
auth/
payment/
notification/
Prefer trunk-based with path-based CI.
Microservice rule
Do not use branches to coordinate service compatibility.
Use:
- API contracts
- backward compatibility
- versioned APIs
- feature flags
- consumer-driven contract tests
47. Branching model for libraries and SDKs
Libraries need stronger version discipline.
Recommended branches
main
release/*
support/*
hotfix/*
Rules
- Use Semantic Versioning.
- Tag every release.
- Maintain support branches for old major versions if needed.
- Breaking changes require major version.
- Patch fixes can be backported.
Example
main โ v3 development
support/2.x โ v2 patches
support/1.x-lts โ v1 long-term support
48. Branching model for mobile apps
Mobile apps often need release branches because app store approval and staged rollout take time.
Recommended branches
main
feature/*
release/ios-4.8.0
release/android-4.8.0
hotfix/*
Mobile release flow
flowchart TD
A[main] --> B[release/mobile-4.8.0]
B --> C[QA]
C --> D[App store submission]
D --> E[Approval]
E --> F[Production rollout]
F --> G[tag v4.8.0]
Code language: CSS (css)
Rules
- Release branch only receives stabilization fixes.
- Main continues future work.
- Hotfixes may require patch release branch.
- Tags must match shipped builds.
49. Branching model for regulated systems
Regulated environments require evidence.
Branch structure
main
release/*
hotfix/*
support/*
Required controls
- protected branches
- required reviewers
- required CI
- signed commits, if required
- release approval
- deployment evidence
- rollback plan
- audit logs
Evidence chain
flowchart LR
A[Ticket] --> B[Branch]
B --> C[Commit]
C --> D[PR approval]
D --> E[CI result]
E --> F[Release tag]
F --> G[Deployment record]
G --> H[Audit trail]
Code language: CSS (css)
50. Branching anti-patterns
Anti-pattern 1: Permanent feature branches
feature/new-platform lives for 6 months
Code language: JavaScript (javascript)
Problem:
- impossible merge
- hidden bugs
- no continuous integration
- team fear
Fix:
- split work
- use feature flags
- use branch by abstraction
- merge small pieces
Anti-pattern 2: Develop branch as dumping ground
main is stable
develop is chaos
Problem:
- develop is always broken
- release branch starts from unstable base
- no one owns quality
Fix:
- protect
develop - require CI
- or remove
developif unnecessary
Anti-pattern 3: Environment branches with direct fixes
fix directly in production branch
forget to merge back
Problem:
- branches drift
- fixes disappear
- staging no longer represents production
Fix:
- hotfix branch from production
- merge/cherry-pick back
- automate branch diff checks
Anti-pattern 4: Branching instead of feature flags
Problem:
Big feature not ready, branch stays open forever
Fix:
Merge incomplete code behind disabled flag
Anti-pattern 5: Release branch gets new features
Problem:
release/2.0 becomes develop-2
Fix:
Release branch accepts only stabilization changes
Anti-pattern 6: No branch deletion
Problem:
300 stale branches
Nobody knows what is active
Fix:
- auto-delete merged branches
- prune stale branches
- archive old release branches deliberately
- review old branches monthly
51. Branch by abstraction
Branch by abstraction is a technique for avoiding long-running branches during large changes.
flowchart TD
A[Old implementation] --> B[Create abstraction layer]
B --> C[Route old behavior through abstraction]
C --> D[Add new implementation behind flag]
D --> E[Migrate callers gradually]
E --> F[Remove old implementation]
Code language: CSS (css)
Example
Instead of:
feature/new-payment-provider lives for 2 months
Code language: JavaScript (javascript)
Do:
PR 1: add PaymentProvider interface
PR 2: route old provider through interface
PR 3: add new provider behind flag
PR 4: migrate one flow
PR 5: migrate all flows
PR 6: remove old provider
Code language: JavaScript (javascript)
This keeps branches short and integration continuous.
52. Stacked branches
Stacked branches are dependent branches used to split large work.
gitGraph
commit id: "main"
branch pr-1-base
checkout pr-1-base
commit id: "base abstraction"
branch pr-2-api
checkout pr-2-api
commit id: "new api"
branch pr-3-ui
checkout pr-3-ui
commit id: "ui"
Code language: JavaScript (javascript)
Use stacked branches when
- Work has natural layers.
- Each layer can be reviewed independently.
- You want smaller PRs.
- You cannot merge everything at once.
Risk
Stacked branches need careful rebasing and clear reviewer communication.
53. Branching commands cheat sheet
Create branch
git checkout main
git pull --ff-only origin main
git checkout -b feature/add-search
Push branch
git push -u origin feature/add-search
Update branch from main
Merge option:
git fetch origin
git merge origin/main
Rebase option:
git fetch origin
git rebase origin/main
Delete branch
Local:
git branch -d feature/add-search
Remote:
git push origin --delete feature/add-search
Code language: JavaScript (javascript)
List branches
git branch
git branch -a
git branch --merged
Prune old remote branches
git fetch --prune
54. Branching model policy template
Use this as a company-ready standard.
Source Control Branching Policy
1. main is the primary integration branch.
2. main must always be healthy and releasable.
3. Direct push to main is not allowed.
4. All changes must use pull requests or merge requests.
5. CI must pass before merge.
6. At least one approval is required.
7. CODEOWNERS approval is required for critical paths.
8. Feature branches must be short-lived.
9. Release branches are created only for stabilization.
10. Hotfix branches are created only for production incidents.
11. Every production release must be tagged.
12. Stale branches must be deleted.
13. Secrets must never be committed.
14. Database and infrastructure changes require explicit review.
15. Rollback strategy must be known before production deployment.
Code language: JavaScript (javascript)
55. Branching model examples
55.1 Simple SaaS team
main
feature/*
bugfix/*
hotfix/*
Model:
GitHub Flow or trunk-based with PRs
Code language: JavaScript (javascript)
Use when:
- frequent deploys
- good CI
- feature flags available
- main always deployable
55.2 Enterprise app with staging and production
main
feature/*
release/*
hotfix/*
Model:
GitLab Flow style with release/environment promotion
Code language: JavaScript (javascript)
Use when:
- staging validation required
- production approval required
- releases are controlled
55.3 Mobile app
main
feature/*
release/ios-5.0.0
release/android-5.0.0
hotfix/*
Model:
Release branch / Gitflow-inspired
Use when:
- app store approval exists
- release candidates matter
- shipped versions need tags
55.4 Terraform repository
main
feature/*
hotfix/*
Model:
Feature branch + protected main + plan checks
Code language: PHP (php)
Use when:
- every infra change requires plan review
- production apply is controlled
- environments are folders or workspaces, not random branches
55.5 Kubernetes GitOps
main
feature/*
Repository:
clusters/dev
clusters/staging
clusters/prod
Model:
GitOps with environment folders
Code language: JavaScript (javascript)
Use when:
- Argo CD or Flux syncs from Git
- desired state is versioned
- promotion is PR-based
56. Branching model governance
A serious branching model must be enforceable.
Governance controls
| Control | Purpose |
|---|---|
| Branch protection | Prevent unsafe merges |
| Required CI | Block broken code |
| Required reviews | Human approval |
| CODEOWNERS | Expert ownership |
| Signed commits | Provenance |
| Release tags | Traceability |
| Auto-delete branches | Hygiene |
| Secret scanning | Security |
| Audit logs | Compliance |
| Deployment gates | Production safety |
57. Branching model metrics
Measure the health of your branching model.
| Metric | What it reveals |
|---|---|
| Average branch age | Integration delay |
| Number of stale branches | Repository hygiene |
| PR size | Review quality |
| PR cycle time | Delivery speed |
| CI failure rate | Code quality |
| Merge conflict frequency | Branch drift |
| Revert rate | Change risk |
| Hotfix frequency | Release quality |
| Deployment frequency | Delivery maturity |
| Change failure rate | Production safety |
Healthy targets
| Metric | Healthy signal |
|---|---|
| Feature branch age | 1โ3 days |
| PR size | small and focused |
| Main branch status | green most of the time |
| Stale branches | low |
| Hotfix rate | decreasing |
| Revert process | fast and safe |
58. The branching model decision matrix
| Situation | Recommended model |
|---|---|
| โWe deploy several times per day.โ | Trunk-based |
| โWe deploy weekly with PR review.โ | GitHub Flow |
| โWe need staging before production.โ | GitLab Flow |
| โWe ship mobile apps.โ | Release branches or Gitflow |
| โWe support older versions.โ | Support/LTS branches |
| โWe are open source.โ | Fork-based |
| โWe use Kubernetes GitOps.โ | Main + environment folders |
| โWe have a monorepo.โ | Trunk-based + CODEOWNERS |
| โWe have weak CI.โ | Feature branches first, improve CI |
| โWe are regulated.โ | Release branches + strict approvals |
| โWe use Terraform.โ | Protected main + plan PRs |
| โWe have giant binary files.โ | Consider Perforce/locking model |
59. The ultimate branching blueprint
For most serious engineering teams, this is the ideal starting architecture:
flowchart TD
A[Work item] --> B[Create short-lived branch]
B --> C[Small commits]
C --> D[Push branch]
D --> E[Open PR/MR]
E --> F[CI checks]
E --> G[Code review]
F --> H{Pass?}
G --> I{Approved?}
H -- No --> C
I -- No --> C
H -- Yes --> J[Merge to protected main]
I -- Yes --> J
J --> K[Build immutable artifact]
K --> L[Deploy to lower environment]
L --> M{Release needed?}
M -- Continuous deploy --> N[Deploy production]
M -- Stabilization needed --> O[Create release branch]
O --> P[QA + fixes only]
P --> Q[Tag release]
Q --> N
N --> R[Monitor]
R --> S{Issue?}
S -- Yes --> T[Hotfix/revert/rollback]
S -- No --> U[Complete]
Code language: PHP (php)
Branch set
main
feature/*
bugfix/*
hotfix/*
release/*
support/* only when needed
Main policy
main is protected, tested, reviewed, and always releasable.
Code language: PHP (php)
Feature policy
Feature branches are short-lived and merged through PR/MR.
Release policy
Release branches exist only for stabilization and version control.
Hotfix policy
Hotfix branches exist only for urgent production repair.
Support policy
Support branches exist only for maintained older versions.
60. Final wisdom
A weak branching model creates confusion.
A good branching model creates flow.
A great branching model makes the safe path the easy path.
The best model is not the most complex one. It is the one that matches:
- team size
- release cadence
- product risk
- deployment style
- CI maturity
- review culture
- compliance needs
- rollback ability
For most modern teams, start with:
Protected main
Short-lived feature branches
Pull requests / merge requests
Required CI
Required review
Release branches only when needed
Hotfix branches for production emergencies
Tags for production releases
Feature flags for incomplete work
Automatic branch cleanup
Code language: PHP (php)
Then evolve toward trunk-based development as your team improves CI, testing, feature flags, deployment automation, and rollback confidence.
The final principle:
Branches should reduce risk, not create bureaucracy.
A branch is useful only when it gives the team one of these benefits:
- safer collaboration
- cleaner review
- controlled release
- emergency repair
- support for older versions
- environment promotion
- production traceability
If it does not do one of those things, delete it, simplify it, or replace it with automation.
Iโm a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at WIZBRAND
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals