Branching_Strategies
Branching Strategies
Popular branching models for different team sizes.
π³ Overview
graph LR
A[Branching Strategy] --> B[Git Flow]
A --> C[GitHub Flow]
A --> D[Trunk-Based]
A --> E[GitLab Flow]
π΅ Git Flow
Best for: Scheduled releases, larger teams
Branches
| Branch | Purpose |
|---|---|
main |
Production releases |
develop |
Integration branch |
feature/* |
New features |
release/* |
Release preparation |
hotfix/* |
Production fixes |
Start Feature Branch
git checkout develop
First, switch to develop branch.
git pull origin develop
Get latest changes.
git checkout -b feature/user-auth
Create feature branch from develop.
Finish Feature Branch
git checkout develop
Switch to develop.
git merge --no-ff feature/user-auth
Merge feature with no fast-forward.
git branch -d feature/user-auth
Delete feature branch.
π’ GitHub Flow
Best for: Continuous delivery, smaller teams
Branches
| Branch | Purpose |
|---|---|
main |
Always deployable |
feature-* |
Any change |
Create Feature Branch
git checkout main
Switch to main.
git pull origin main
Get latest.
git checkout -b feature-add-login
Create feature branch.
Work and Push
git add .
Stage changes.
git commit -m "Add login feature"
Commit work.
git push -u origin feature-add-login
Push branch.
Create Pull Request
gh pr create --fill
Create PR using GitHub CLI.
After Merge
git checkout main
Switch to main.
git pull origin main
Get merged changes.
git branch -d feature-add-login
Delete local branch.
π‘ Trunk-Based Development
Best for: High-velocity teams, continuous integration
Branches
| Branch | Purpose |
|---|---|
main (trunk) |
All development |
| Short-lived branches | < 1 day |
Short-Lived Branch
git checkout -b quick-fix
Create short-lived branch.
git commit -am "Quick fix"
Make changes.
git checkout main && git merge quick-fix
Merge quickly.
Direct to Main
git checkout main
Work directly on main.
git pull --rebase
Rebase before pushing.
git push
Push directly.
π Strategy Comparison
| Aspect | Git Flow | GitHub Flow | Trunk-Based |
|---|---|---|---|
| Complexity | High | Low | Low |
| Release cycle | Scheduled | Continuous | Continuous |
| Team size | Large | Small-Medium | Any |
| Branch lifetime | Long | Short | Very short |
π‘ Choosing a Strategy
Use GitHub Flow unless you have specific needs for Git Flow.
Trunk-based works best with strong CI/CD and feature flags.
π Related
#git #branching #strategy #workflow