From Beginner to Advanced: A Complete One-Stop Guide to Choosing, Designing, and Governing Branches
1. What is a branching strategy?
A branching strategy is a teamโs rulebook for how branches are created, used, reviewed, merged, released, protected, and deleted.
It answers:
- Which branch is production?
- Which branch do developers start from?
- How long can a branch live?
- When do we create feature branches?
- When do we create release branches?
- When do we create hotfix branches?
- Do we use
main,develop,release/*,hotfix/*, or only trunk? - How do changes move from development to production?
- How do we avoid merge hell?
- How do we support old versions?
- How do we roll back safely?
- How do CI/CD, code review, and branch protection fit?
Simple definition:
A branching strategy is the traffic control system for software changes.
A weak strategy creates chaos.
A good strategy creates flow.
A great strategy lets teams move fast without making production fragile.
2. Branching strategy vs Git workflow vs software delivery workflow
These are related, but not the same.
| Term | Meaning | Example |
|---|---|---|
| Branching strategy | How branches are structured and merged | Gitflow, trunk-based, GitHub Flow |
| Git workflow | How developers use Git day to day | branch โ commit โ PR โ merge |
| Version control workflow | Complete source-control process | commits, branches, tags, reviews |
| Software delivery workflow | Full path from idea to production | plan โ code โ test โ deploy โ observe |
| Release strategy | How versions are shipped | tags, release branches, canary, blue-green |
Branching strategy is one layer inside the wider delivery system.
flowchart TD
A[Software Delivery Workflow] --> B[Version Control Workflow]
B --> C[Git Workflow]
C --> D[Branching Strategy]
D --> E[Branch Names, Merge Rules, Release Rules, Hotfix Rules]
Code language: CSS (css)
3. Why branching strategy matters
Bad branching causes:
- long merge conflicts
- broken
main - unclear production state
- duplicated work
- unstable release branches
- forgotten hotfixes
- huge pull requests
- slow delivery
- risky production releases
- environment drift
- unclear rollback
Good branching creates:
- safe collaboration
- faster review
- predictable releases
- cleaner history
- lower production risk
- easier hotfixes
- better CI/CD
- better audit trail
- simpler rollback
- happier engineers
The official Git book describes branching and merging as normal daily operations, including creating a branch for work, switching to a hotfix, and merging completed work back.
4. The most important mental model
A branch is not a place to hide work forever.
A branch is a temporary safety boundary.
Branch = temporary isolation for a clear purpose
Every branch must answer:
Why does this branch exist?
What risk does it isolate?
When will it be merged or deleted?
Who owns it?
Code language: JavaScript (javascript)
If nobody can answer those questions, the branch is probably technical garbage slowly fossilizing in your repository. Tiny archaeology site. Bad vibes.
5. The five reasons branches exist
Most branches exist for one of five reasons.
| Purpose | Branch type | Example |
|---|---|---|
| New work | Feature branch | feature/add-login |
| Normal bug fix | Bugfix branch | bugfix/payment-timeout |
| Production emergency | Hotfix branch | hotfix/prod-crash |
| Release stabilization | Release branch | release/2.4.0 |
| Old version support | Support branch | support/1.9-lts |
If a branch does not support development, review, release, hotfix, or support, question it.
6. Core branch types
6.1 main / master / trunk
This is the primary integration branch.
Modern repositories usually use:
main
Older repositories may still use:
master
Trunk-based teams may call it:
trunk
In trunk-based development, teams collaborate around a single branch called trunk, main, or mainline, avoiding long-running development branches.
6.2 Feature branch
Used for new work.
feature/add-user-login
feature/device-search
feature/report-export
Code language: JavaScript (javascript)
Feature branches should be short-lived. The trunk-based development reference describes short-lived feature branches as branches intended to come back as pull requests into trunk/main.
6.3 Bugfix branch
Used for non-emergency defects.
bugfix/login-timeout
bugfix/wrong-invoice-total
bugfix/api-null-response
Code language: JavaScript (javascript)
6.4 Hotfix branch
Used for urgent production repair.
hotfix/payment-crash
hotfix/security-token-leak
hotfix/prod-login-failure
Hotfix branches must be small, focused, quickly reviewed, and merged back into every active branch that needs the fix.
6.5 Release branch
Used to stabilize a version before shipping.
release/1.5.0
release/2026.07
release/mobile-4.2.0
Release branches are useful when QA, certification, app-store approval, enterprise release windows, or version support require a controlled stabilization line.
6.6 Support / LTS branch
Used to maintain old versions.
support/1.9-lts
support/2.x
maintenance/2025-lts
These branches exist when customers or systems cannot immediately upgrade to the newest version.
6.7 Environment branch
Used when branches map directly to environments.
dev
staging
production
GitLabโs documentation lists branch-per-environment as one possible branching strategy, alongside web-service and long-lived release-branch approaches.
Environment branches can work, but they can also drift badly if teams make direct changes in different branches.
7. The lifecycle of a healthy branch
flowchart TD
A[Create from correct base] --> B[Make small commits]
B --> C[Push branch]
C --> D[Open PR/MR]
D --> E[CI checks]
D --> F[Code review]
E --> G{Checks pass?}
F --> H{Approved?}
G -- No --> B
H -- No --> B
G -- Yes --> I[Merge]
H -- Yes --> I
I --> J[Delete branch]
Code language: JavaScript (javascript)
Healthy branches are:
- clearly named
- short-lived
- owned
- reviewed
- tested
- merged
- deleted
Unhealthy branches are:
- old
- unclear
- huge
- unreviewed
- never merged
- never deleted
- impossible to rebase
- terrifying to touch
8. Branch lifetime guide
| Branch type | Ideal lifetime | Maximum recommended lifetime |
|---|---|---|
feature/* | Hours to 3 days | 1 week |
bugfix/* | Hours to 2 days | 1 week |
hotfix/* | Minutes to hours | 1 day |
release/* | Days to weeks | Release-dependent |
support/* | Months to years | Product-dependent |
experiment/* | Hours to days | 1โ2 weeks |
| Environment branch | Long-lived | Must be strictly governed |
xychart-beta
title "Branch age vs merge risk"
x-axis ["Hours", "1 day", "3 days", "1 week", "2 weeks", "1 month"]
y-axis "Integration risk" 0 --> 100
bar [5, 10, 25, 45, 75, 95]
Code language: JavaScript (javascript)
The chart is conceptual, but the lesson is painfully real:
Long-lived branches do not remove integration pain.
They delay it and make it bigger.
Code language: JavaScript (javascript)
9. The major branching strategies
The major strategies are:
- Mainline strategy
- Feature branch strategy
- GitHub Flow
- GitLab Flow
- Gitflow
- Trunk-based development
- Release branch strategy
- Environment branch strategy
- Fork-based strategy
- GitOps branching strategy
- Monorepo branching strategy
- Support/LTS strategy
mindmap
root((Branching Strategies))
Mainline
Feature Branch
GitHub Flow
GitLab Flow
Gitflow
Trunk Based Development
Release Branch
Environment Branch
Fork Based
GitOps
Monorepo
Support LTS
10. Strategy 1: Mainline strategy
What it is
Everyone works close to one main branch.
main
gitGraph
commit id: "A"
commit id: "B"
commit id: "C"
commit id: "D"
Code language: JavaScript (javascript)
Best for
- solo developers
- prototypes
- small internal tools
- learning repositories
- scripts
- tiny teams with strong discipline
Pros
| Benefit | Explanation |
|---|---|
| Simple | Few branches |
| Fast | No complex promotion |
| Easy to understand | Good for beginners |
Cons
| Risk | Explanation |
|---|---|
| Easy to break main | If no reviews/checks |
| Weak governance | No release structure |
| Risky for large teams | Too much direct integration |
Recommended rules
main must always build
commit small
pull before push
use CI
tag important versions
avoid direct production deployment from laptops
Code language: JavaScript (javascript)
Verdict
Mainline is fine for small/simple work. For professional teams, add PRs, CI, and branch protection quickly.
11. Strategy 2: Feature branch strategy
What it is
Each task gets its own temporary branch.
main
feature/*
bugfix/*
hotfix/*
gitGraph
commit id: "main-1"
branch feature/login
checkout feature/login
commit id: "login-1"
commit id: "login-2"
checkout main
merge feature/login
branch bugfix/payment
checkout bugfix/payment
commit id: "fix-payment"
checkout main
merge bugfix/payment
Code language: JavaScript (javascript)
Workflow
flowchart LR
A[main] --> B[feature branch]
B --> C[PR/MR]
C --> D[CI + review]
D --> E[merge to main]
E --> F[delete branch]
Code language: CSS (css)
Best for
- most engineering teams
- backend services
- frontend apps
- Terraform repositories
- Kubernetes manifests
- documentation
- teams not ready for full trunk-based development
Pros
| Benefit | Explanation |
|---|---|
| Clear isolation | Work does not immediately affect main |
| PR-friendly | Natural review workflow |
| Beginner-friendly | Easy to understand |
| Works with CI/CD | Good default |
Cons
| Risk | Explanation |
|---|---|
| Branches can live too long | Creates merge conflicts |
| Huge PRs | Review quality drops |
| Delayed feedback | Problems appear late |
Best practice
Keep feature branches short-lived and PRs small.
12. Strategy 3: GitHub Flow
What it is
GitHub Flow is a lightweight branch-based workflow. GitHubโs official documentation describes it as: create a branch, make changes, create a pull request, address review comments, merge, and delete the branch.
flowchart LR
A[Create branch] --> B[Make commits]
B --> C[Open pull request]
C --> D[Review and discuss]
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 applications
- SaaS products
- APIs
- documentation sites
- internal tools
- teams that deploy frequently
Not ideal for
- mobile app-store release cycles
- desktop software with long release windows
- firmware
- heavy certification processes
- products supporting many old versions
Practical policy
Branch from main.
Open pull request.
Require CI and review.
Merge to main.
Deploy from main.
Delete branch.
Code language: JavaScript (javascript)
13. Strategy 4: GitLab Flow
What it is
GitLab Flow adds deployment, environment, and release guidance around feature branches and merge requests. 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 variants
Variant A: Main + production branch
main
production
Variant B: Environment branches
main
staging
production
Variant C: Release branches
main
release/1.0
release/1.1
release/2.0
GitLabโs branching-strategy documentation describes models for web services, long-lived release branches, and branch-per-environment workflows.
Best for
- teams using GitLab
- staging โ production promotion
- enterprise web apps
- release visibility
- teams wanting more structure than GitHub Flow but less ceremony than Gitflow
Strength
GitLab Flow is a practical middle ground.
It says:
Keep development simple, but make deployment and release state explicit.
14. Strategy 5: Gitflow
What it is
Gitflow is a structured branching model with multiple long-lived and short-lived branches.
Typical branches:
main
develop
feature/*
release/*
hotfix/*
Atlassian describes Gitflow as assigning specific roles to branches such as feature, release, and hotfix branches, and notes that it is suitable for projects with scheduled release cycles.
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/* | Release stabilization |
hotfix/* | Emergency production repair |
support/* | Optional old-version maintenance |
Best for
- mobile apps
- desktop apps
- firmware
- SDKs
- on-prem software
- scheduled release cycles
- products needing formal release stabilization
- teams supporting old versions
Pros
| Benefit | Explanation |
|---|---|
| Very structured | Clear branch purpose |
| Release-friendly | Good for versioned products |
| Hotfix-friendly | Production repair path is explicit |
| Governance-friendly | Works with formal approval |
Cons
| Risk | Explanation |
|---|---|
| More complex | Many branch types |
| Slower | More merging and coordination |
develop can rot | If not protected |
| Long-lived branches | More conflict risk |
| Overkill for SaaS | Continuous delivery teams often do not need it |
Verdict
Gitflow is powerful when release complexity is real.
It is overkill when a team can safely deploy from main.
15. Strategy 6: Trunk-based development
What it is
Trunk-based development means developers integrate small changes into one shared trunk frequently. The trunk-based development reference strongly recommends trunk-based development over models with multiple long-running branches and allows either direct-to-trunk commits for very small teams 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/*
Core rule
The trunk is the center of gravity.
Branches are temporary.
Best for
- mature CI/CD teams
- SaaS
- APIs
- platform teams
- monorepos
- high-frequency deployment
- teams using feature flags
- teams with strong automated tests
Required practices
| Practice | Why |
|---|---|
| Small PRs | Easier review |
| Fast CI | Quick feedback |
| Feature flags | Hide incomplete work |
| Strong tests | Protect trunk |
| Quick rollback | Recover safely |
| Short branch life | Avoid merge pain |
Warning
Trunk-based development does not mean chaos.
Bad trunk-based:
Everyone pushes random code to main.
Good trunk-based:
Small changes, strong CI, feature flags, protected main, fast rollback.
Code language: PHP (php)
16. Strategy 7: Release branch strategy
What it is
A release branch stabilizes a version while normal development continues elsewhere.
main
release/2.4.0
gitGraph
commit id: "A"
commit id: "B"
branch release/2.4.0
checkout release/2.4.0
commit id: "rc-fix-1"
commit id: "rc-fix-2"
checkout main
commit id: "future-work"
checkout release/2.4.0
commit id: "release-ready" tag: "v2.4.0"
Code language: JavaScript (javascript)
Best for
- QA cycles
- app-store approvals
- enterprise release windows
- certification
- customer-specific versions
- release candidates
- controlled production promotion
Release branch rules
Allowed:
bug fixes
version bumps
release notes
safe documentation updates
release configuration fixes
Not allowed:
new features
large refactors
experimental changes
unrelated cleanup
risky dependency upgrades
Code language: JavaScript (javascript)
Good release branch naming
release/2.4.0
release/2026.07
release/mobile-5.1.0
17. Strategy 8: Environment branch strategy
What it is
Branches represent environments.
dev
staging
production
flowchart LR
A[dev] --> B[staging]
B --> C[production]
Code language: CSS (css)
Best for
- simple deployment triggers
- teams already using branch-based deployment
- some GitLab Flow setups
- smaller systems with strict promotion rules
Major risk: 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 rules
If you use environment branches:
- Promotion direction must be clear.
- Never make random direct changes in production branch.
- Hotfixes must flow back to lower branches.
- CI must validate every promotion.
- Branch differences must be visible.
- Staging must not become a different product from production.
Better alternative for many teams
main branch + environment folders + deployment pipeline
Example:
environments/
dev/
staging/
production/
18. Strategy 9: Fork-based strategy
What it is
Contributors fork the repository, work in their fork, and open pull requests 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
- vendors
- public repositories
- situations where contributors should not have write access
Typical flow
fork repo
create branch in fork
push changes
open pull request to upstream
maintainer reviews
merge
19. Strategy 10: GitOps branching strategy
What it is
GitOps uses Git as the desired state for infrastructure or application deployment.
flowchart LR
A[App source repo] --> B[Build image]
B --> C[Push image]
C --> D[Update GitOps repo]
D --> E[Argo CD / Flux sync]
E --> F[Kubernetes cluster]
Code language: CSS (css)
Recommended layout
gitops/
apps/
auth/
payment/
notification/
environments/
dev/
staging/
production/
platform/
ingress/
monitoring/
security/
Best practice
For most GitOps teams:
Use one main branch and environment folders.
Code language: PHP (php)
This is often cleaner than long-lived environment branches.
Golden GitOps rule
Build once. Promote the same artifact.
20. Strategy 11: Monorepo branching strategy
What it is
A monorepo stores many apps, services, packages, and infrastructure code in one repository.
repo/
apps/
web/
admin/
services/
auth/
payment/
notification/
packages/
common/
ui/
infra/
docs/
Recommended strategy
trunk-based development
short-lived branches
CODEOWNERS
path-based CI
affected-project builds
feature flags
flowchart TD
A[Change in monorepo] --> B[Detect changed paths]
B --> C[Find affected projects]
C --> D[Run targeted tests]
D --> E[Request CODEOWNERS review]
E --> F[Merge to main]
F --> G[Build affected artifacts]
Code language: CSS (css)
Why trunk-based works well in monorepos
Long-lived branches in monorepos are especially painful because many teams touch the same repository. Short-lived branches and fast integration reduce conflict risk.
21. Strategy 12: Support / LTS branching strategy
What it is
Support branches maintain older versions.
main
release/3.0
support/2.x
support/1.9-lts
flowchart LR
A[main] --> B[release/3.0]
A --> C[support/2.x]
A --> D[support/1.9-lts]
E[Security fix] --> B
E --> C
E --> D
Code language: CSS (css)
Best for
- enterprise products
- SDKs
- libraries
- firmware
- operating-system-like products
- products with long customer upgrade cycles
Backport rule
A fix should be backported when it is:
- security-related
- data-loss-related
- production-crash-related
- compliance-related
- customer-critical
Do not backport random refactors or new features unless there is a strong business reason.
22. Comparing branching strategies
| Strategy | Speed | Governance | Complexity | Best for |
|---|---|---|---|---|
| Mainline | High | Low | Low | Tiny teams |
| Feature branch | Medium-high | Medium | Medium | Most teams |
| GitHub Flow | High | Medium | Low-medium | SaaS/web apps |
| GitLab Flow | Medium | High | Medium | Env promotion |
| Gitflow | Medium-low | High | High | Versioned releases |
| Trunk-based | Very high | High if automated | Medium-high | Mature CI/CD |
| Release branch | Medium | High | Medium | QA/release windows |
| Environment branch | Low-medium | Medium | Medium-high | Branch deploys |
| Fork-based | Medium | High | Medium | Open source |
| GitOps | High | High | Medium | Kubernetes/platform |
| Monorepo trunk | Very high | High | High tooling | Large repos |
| Support/LTS | Low-medium | Very high | High | Old versions |
23. Strategy decision tree
flowchart TD
A[Choose branching strategy] --> B{External contributors?}
B -- Yes --> C[Fork-based strategy]
B -- No --> D{Do you deploy many times per week?}
D -- Yes --> E{Strong CI, tests, feature flags?}
E -- Yes --> F[Trunk-based development]
E -- No --> G[GitHub Flow or feature branch strategy]
D -- No --> H{Scheduled versioned releases?}
H -- Yes --> I{Need develop + release + hotfix structure?}
I -- Yes --> J[Gitflow]
I -- No --> K[Release branch strategy]
H -- No --> L{Need staging to production promotion?}
L -- Yes --> M[GitLab Flow or GitOps environment folders]
L -- No --> N[Feature branch strategy]
Code language: PHP (php)
24. Recommended strategy by project type
| Project type | Recommended strategy |
|---|---|
| Solo project | Mainline |
| Small internal tool | GitHub Flow |
| SaaS backend | Trunk-based or GitHub Flow |
| Enterprise web app | GitLab Flow |
| Mobile app | Release branches or Gitflow |
| Desktop app | Gitflow |
| Firmware | Gitflow + support branches |
| SDK/library | Release branches + SemVer |
| Terraform IaC | Feature branches + protected main |
| Kubernetes GitOps | Main + environment folders |
| Open source | Fork-based |
| Monorepo | Trunk-based + CODEOWNERS |
| Regulated system | Release branches + strict approval |
| Long-term enterprise product | Support/LTS branches |
AWS Prescriptive Guidance groups common Git branching choices around trunk, GitHub Flow, and Gitflow and recommends choosing based on organizational needs.
25. The best default strategy for most modern teams
For most teams, start with this:
main
feature/*
bugfix/*
hotfix/*
release/* only when needed
Rules
mainis always healthy.- No direct push to
main. - Every change goes through PR/MR.
- CI must pass before merge.
- At least one approval is required.
- Feature branches are short-lived.
- Release branches are created only for stabilization.
- Hotfix branches are created only for production emergencies.
- Branches are deleted after merge.
- Every production release is tagged.
GitHub protected branch rules can prevent force pushes or deletion and can require status checks, pull request reviews, or linear history before changes land.
26. 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 prefix guide
| Prefix | Purpose |
|---|---|
feature/ | New functionality |
bugfix/ | Normal bug fix |
hotfix/ | Urgent production fix |
release/ | Release stabilization |
support/ | Old-version maintenance |
docs/ | Documentation |
chore/ | Maintenance |
refactor/ | Internal restructuring |
security/ | Security fix |
experiment/ | Temporary exploration |
test/ | Test-only change |
27. Branch protection strategy
Branching strategy is useless if it is not enforced.
Recommended branch protection
| Branch | Protection level |
|---|---|
main | Very strong |
release/* | Strong |
hotfix/* | Fast but controlled |
develop | Strong if used |
production | Very strong |
support/* | Strong |
feature/* | Usually light |
main protection checklist
- direct push disabled
- pull request required
- required CI checks
- required approvals
- CODEOWNERS for critical paths
- force push disabled
- branch deletion disabled
- signed commits if needed
- admin bypass audited
GitHub branch protection rules can enforce required reviews and passing status checks for pull requests before merge.
28. Merge strategy
A branching strategy must define how branches merge.
Merge options
| Merge type | Meaning | Best for |
|---|---|---|
| Merge commit | Preserve full branch history | Audit-heavy teams |
| Squash merge | One PR becomes one commit | Clean main |
| Rebase merge | Replay commits linearly | Teams with strong Git discipline |
| Fast-forward | Move pointer only | Trunk/mainline workflows |
Gitโs documentation explains that git merge integrates another branch into the currently checked-out branch.
Recommended default
Normal feature PRs: squash merge
Release branches: merge commit
Hotfix branches: merge commit or squash depending audit need
Local cleanup: rebase your own branch
Shared branch: do not rebase casually
Code language: JavaScript (javascript)
29. Merge vs rebase
| Area | Merge | Rebase |
|---|---|---|
| History | Preserves branch structure | Rewrites branch commits |
| Safety | Safer for shared branches | Safer for local cleanup |
| Readability | Can be noisy | Linear and clean |
| Conflict handling | Usually one merge conflict event | May resolve conflicts commit by commit |
| Best use | Shared integration | Cleaning your own branch |
Safe rule
Rebase your own branch.
Do not rebase shared branches unless the team explicitly agrees.
Code language: PHP (php)
30. Release branch strategy in detail
A release branch exists to stabilize a version.
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:
fixes
version bump
release notes
safe documentation
release config correction
Not allowed:
new feature
big refactor
experimental dependency
unrelated cleanup
risky architecture change
Code language: JavaScript (javascript)
Release branch commands
git checkout main
git pull --ff-only origin main
git checkout -b release/2.5.0
git push -u origin release/2.5.0
After stabilization:
git checkout main
git merge --no-ff release/2.5.0
git tag -a v2.5.0 -m "Release v2.5.0"
git push origin main v2.5.0
Code language: JavaScript (javascript)
Semantic Versioning defines MAJOR.MINOR.PATCH, where major versions indicate incompatible API changes, minor versions add backward-compatible functionality, and patch versions add backward-compatible bug fixes.
31. Hotfix branch strategy in detail
Hotfix branches fix production fast but safely.
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[Back-merge/cherry-pick to active branches]
Code language: CSS (css)
Hotfix rules
- Start from the production branch or production tag.
- Fix only the incident.
- Avoid refactoring.
- Avoid unrelated dependency upgrades.
- Keep PR small.
- Run critical CI.
- Deploy.
- Tag the patch release.
- Merge or cherry-pick back to
main,develop, or active release branches. - Create follow-up cleanup ticket if needed.
Hotfix commands
git checkout main
git pull --ff-only origin main
git checkout -b hotfix/2.5.1-payment-crash
After fix:
git add .
git commit -m "fix(payment): prevent crash on missing token"
git push -u origin hotfix/2.5.1-payment-crash
Code language: JavaScript (javascript)
After merge:
git checkout main
git pull --ff-only origin main
git tag -a v2.5.1 -m "Hotfix v2.5.1"
git push origin v2.5.1
Code language: CSS (css)
32. Support branch and backport strategy
Support branches exist when old versions need fixes.
flowchart LR
A[Fix in main] --> B[Backport to release/3.0]
A --> C[Backport to support/2.x]
A --> D[Backport to support/1.9-lts]
B --> E[Tag v3.0.4]
C --> F[Tag v2.8.9]
D --> G[Tag v1.9.17]
Code language: CSS (css)
Backport decision table
| Change type | Backport? |
|---|---|
| Security vulnerability | Yes |
| Data loss | Yes |
| Production crash | Usually yes |
| Compliance issue | Yes |
| Minor UI bug | Maybe |
| New feature | Usually no |
| Refactor | No |
Backport command
git checkout support/2.x
git cherry-pick <fix-commit-sha>
git push origin support/2.x
Code language: HTML, XML (xml)
33. Branching and CI/CD
Branches should trigger different CI/CD behavior.
flowchart TD
A[Branch pushed] --> B{Branch type?}
B -- feature/* --> C[Lint + unit test + build]
B -- main --> D[Full CI + deploy staging]
B -- release/* --> E[Release validation]
B -- hotfix/* --> F[Critical tests + fast checks]
B -- production --> G[Production deploy]
B -- support/* --> H[Version-specific tests]
Recommended pipeline behavior
| Branch | Pipeline |
|---|---|
feature/* | lint, unit tests, build |
bugfix/* | lint, unit tests, build |
main | full CI, integration tests, deploy lower env |
release/* | full regression/release validation |
hotfix/* | critical CI, security check |
support/* | compatibility tests |
production | deploy only from approved artifact |
34. Branching and feature flags
Feature flags are the secret weapon that lets teams keep branches short.
Without flags:
Feature not ready โ keep branch open for weeks
With flags:
Feature not ready โ merge safely behind disabled flag
flowchart TD
A[Small feature branch] --> B[Code behind feature flag]
B --> C[Merge to main]
C --> D[Deploy with flag OFF]
D --> E[Enable internally]
E --> F[Enable 10%]
F --> G[Enable 100%]
G --> H[Remove old flag]
Code language: CSS (css)
Feature flag rules
- Every flag has an owner.
- Every flag has an expiry date.
- Critical flags are monitored.
- Old flags are removed.
- Flag changes are auditable.
- Flags should not become permanent configuration junk.
35. Branching and database migrations
Database migrations can destroy a beautiful branching strategy if handled badly.
Bad pattern
Large feature branch changes schema for 3 weeks.
Meanwhile main changes app behavior.
Release branch needs old schema.
Production hotfix now conflicts.
Safe pattern: 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)
Rules
- Keep migrations small.
- Make schema changes backward compatible.
- Avoid destructive changes in the same release.
- Do not hide database changes inside huge PRs.
- Include rollback or fix-forward plan.
- Test old app + new schema and new app + old schema where needed.
36. Branching strategy for Infrastructure as Code
Infrastructure changes need stronger guardrails than normal app code.
Recommended branch model
main
feature/*
bugfix/*
hotfix/*
Usually avoid long-lived environment branches unless there is a very clear reason.
flowchart TD
A[Create infra branch] --> B[Edit Terraform/Pulumi]
B --> C[Format + validate]
C --> D[Plan]
D --> E[Security scan]
E --> F[Cost/blast-radius review]
F --> G[Approval]
G --> H[Merge]
H --> I[Apply via pipeline]
Code language: CSS (css)
IaC PR must include
- plan summary
- resources created
- resources changed
- resources destroyed
- security impact
- cost impact
- blast radius
- rollback plan
Dangerous plan keywords
destroy
replace
forces replacement
0.0.0.0/0
public access
delete database
disable encryption
remove backup
Code language: JavaScript (javascript)
37. Branching strategy for Kubernetes GitOps
For Kubernetes GitOps, avoid making branches too clever.
Recommended model
main
feature/*
Repository layout:
clusters/
dev/
staging/
production/
apps/
auth/
payment/
notification/
platform/
ingress/
monitoring/
security/
Promotion flow
flowchart LR
A[App PR merged] --> B[Build image]
B --> C[Update dev manifest]
C --> D[Promote same image to staging]
D --> E[Promote same image to production]
E --> F[Argo CD / Flux sync]
Code language: CSS (css)
GitOps rule
Git is desired state.
Production changes happen through reviewed Git changes.
38. Branching strategy for microservices
Microservices should not rely on branches to coordinate compatibility.
Use:
- backward-compatible APIs
- contract tests
- versioned endpoints
- feature flags
- independent deployment
- consumer-driven testing
- observability
Bad microservice branching
service-a feature branch waits for service-b feature branch waits for service-c feature branch
This creates distributed merge hell.
Better
flowchart TD
A[Service A change] --> B[Backward-compatible API]
B --> C[Contract tests]
C --> D[Deploy Service A]
D --> E[Monitor consumers]
E --> F[Gradual rollout]
Code language: CSS (css)
39. Branching strategy for monorepos
For monorepos, prefer:
main
short-lived feature branches
trunk-based development
CODEOWNERS
path-based CI
affected-project builds
feature flags
Monorepo branch flow
flowchart TD
A[Change in repo] --> B[Detect changed paths]
B --> C[Find affected services/packages]
C --> D[Run targeted CI]
D --> E[Request CODEOWNERS review]
E --> F[Merge to main]
F --> G[Build/deploy affected artifacts]
Code language: CSS (css)
Monorepo warning
Long-lived branches in monorepos are extra painful because many teams are modifying the same tree.
40. Branching strategy for mobile apps
Mobile apps often need release branches.
Recommended branches
main
feature/*
release/ios-5.0.0
release/android-5.0.0
hotfix/*
Mobile release flow
flowchart TD
A[main] --> B[release/mobile-5.0.0]
B --> C[QA]
C --> D[App store submission]
D --> E[Approval]
E --> F[Staged rollout]
F --> G[tag v5.0.0]
Code language: CSS (css)
Rules
- Release branch receives stabilization fixes only.
- Tags must match shipped builds.
- APIs must remain backward compatible because old app versions stay in the wild.
- Hotfixes may require patch release branches.
41. Branching strategy for libraries and SDKs
Libraries need stronger version discipline.
Recommended branches
main
release/*
support/*
hotfix/*
Rules
- Use Semantic Versioning.
- Tag every release.
- Maintain changelog.
- Backport critical fixes.
- Breaking changes require major version.
- Support branches exist for old major versions if needed.
Example
main โ v4 development
support/3.x โ v3 patches
support/2.x-lts โ v2 long-term support
42. Branching strategy for regulated systems
Regulated systems need traceability.
Recommended branches
main
release/*
hotfix/*
support/*
Required controls
- protected branches
- required reviewers
- CODEOWNERS
- required CI
- release tags
- deployment evidence
- rollback plan
- audit logs
- signed commits if required
- change ticket linkage
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)
43. Branch by abstraction
Branch by abstraction is how advanced teams avoid long-running branches during large changes.
flowchart TD
A[Old implementation] --> B[Create abstraction]
B --> C[Route old implementation 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.
44. Stacked branches
Stacked branches split large work into dependent PRs.
gitGraph
commit id: "main"
branch pr-1-abstraction
checkout pr-1-abstraction
commit id: "abstraction"
branch pr-2-api
checkout pr-2-api
commit id: "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 separately
- one giant PR would be terrible
- changes can land progressively
Risk
Stacked branches require careful rebasing and clear communication.
45. Branching anti-patterns
Anti-pattern 1: Long-lived feature branches
feature/new-platform lives for 3 months
Code language: JavaScript (javascript)
Problem:
- huge merge conflicts
- hidden integration bugs
- delayed feedback
- big-bang release risk
Fix:
- split work
- use feature flags
- use branch by abstraction
- merge small pieces frequently
Anti-pattern 2: develop as a dumping ground
main is stable
develop is chaos
Problem:
developalways broken- releases start from unstable base
- nobody owns quality
Fix:
- protect
develop - require CI
- keep it green
- remove it if not needed
Anti-pattern 3: Environment branches with direct fixes
production branch has hotfix
staging branch does not
main does not
nobody remembers
Fix:
- hotfix branch from production
- merge/cherry-pick back
- automate branch comparison
- never let production become secret code
Anti-pattern 4: Release branch becomes a feature branch
release/2.0 gets new dashboard feature
Code language: JavaScript (javascript)
Fix:
Release branches accept stabilization only.
Anti-pattern 5: No branch deletion
600 remote branches
nobody knows what matters
Fix:
- auto-delete merged branches
- prune stale branches
- archive old release branches deliberately
- review stale branches monthly
Anti-pattern 6: Branching instead of feature flags
Bad:
Keep code unmerged for weeks because feature is not ready.
Good:
Merge safely behind disabled feature flag.
46. Branching metrics
Measure your branching strategy.
| Metric | Meaning |
|---|---|
| Average branch age | Integration delay |
| Stale branch count | Repository hygiene |
| PR size | Review quality |
| PR cycle time | Delivery speed |
| Merge conflict frequency | Branch drift |
| CI failure rate | Quality health |
| Revert rate | Change risk |
| Hotfix frequency | Release quality |
| Deployment frequency | Delivery maturity |
Healthy signals
feature branches live 1โ3 days
PRs are small
main is green
stale branches are low
hotfix rate is decreasing
rollback is fast
47. Branching commands cheat sheet
Create feature 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 deleted remote branches
git fetch --prune
Create release branch
git checkout main
git pull --ff-only origin main
git checkout -b release/2.5.0
git push -u origin release/2.5.0
Create hotfix branch
git checkout main
git pull --ff-only origin main
git checkout -b hotfix/2.5.1-payment-crash
48. Company-ready branching policy
Use this as a strong default.
Branching Strategy 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 go through 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 release stabilization.
10. Hotfix branches are created only for production incidents.
11. Support branches are created only for maintained old versions.
12. Every production release must be tagged.
13. Branches must be deleted after merge.
14. Stale branches must be reviewed regularly.
15. Secrets must never be committed.
16. Infrastructure and database changes require explicit review.
17. Rollback strategy must be known before production deployment.
Code language: JavaScript (javascript)
49. One-page branching standard
Branches
main
feature/*
bugfix/*
hotfix/*
release/*
support/* only when needed
Merge rules
feature/* โ main through PR
bugfix/* โ main through PR
hotfix/* โ main/release/support through emergency PR
release/* โ main and tag
support/* โ patch releases only
Protection rules
main: protected
release/*: protected
support/*: protected
hotfix/*: fast review
feature/*: normal review
Code language: HTTP (http)
Tagging rules
Production release: tag required
Hotfix release: patch tag required
Library release: SemVer tag required
Deletion rules
Merged feature branches: delete
Merged bugfix branches: delete
Old release branches: archive or delete based on policy
Support branches: keep while version is supported
Experiment branches: delete quickly
Code language: JavaScript (javascript)
50. Final branching blueprint
flowchart TD
A[Work item] --> B{Type of work?}
B -- Feature --> C[feature/* from main]
B -- Bugfix --> D[bugfix/* from main]
B -- Production incident --> E[hotfix/* from production tag/main]
B -- Release stabilization --> F[release/*]
B -- Old version fix --> G[support/*]
C --> H[PR + CI + review]
D --> H
E --> I[Emergency PR + critical CI]
F --> J[QA + fixes only]
G --> K[Backport PR]
H --> L[Merge to main]
I --> L
I --> M[Backport if needed]
J --> N[Tag release]
K --> O[Tag patch release]
L --> P[Build artifact]
N --> P
O --> P
P --> Q[Deploy / release]
Q --> R[Observe]
R --> S{Issue?}
S -- Yes --> E
S -- No --> T[Done]
51. Final recommendation
For most teams, the best practical strategy is:
Protected main
Short-lived feature branches
Pull requests / merge requests
Required CI
Required review
Squash merge for normal work
Release branches only when needed
Hotfix branches for production emergencies
Tags for production releases
Feature flags for incomplete work
Branch cleanup after merge
Code language: PHP (php)
Then evolve toward trunk-based development when your team has:
- fast CI
- strong automated tests
- small PR culture
- feature flags
- reliable rollback
- strong observability
- mature review habits
Final principle:
Branches should reduce risk, not create bureaucracy.
A branch is valuable only if it helps with one of these:
- safe collaboration
- clean review
- controlled release
- emergency repair
- old-version support
- environment promotion
- production traceability
If a branch does not do any of those things, simplify the model.
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