Git Branch Strategies
In this page:
Git Flow Strategy
Git Flow is a heavyweight, structured branching model built around parallel develop and main branches, plus dedicated feature/, release/, and hotfix/ branches -- well-suited to projects with scheduled releases, but often overkill for small, fast-moving teams.
Example: Git Flow Strategy
git checkout develop
git checkout -b feature/login
git checkout -b release/1.0 develop
git checkout -b hotfix/critical-bug main
GitHub Flow
GitHub Flow strips that down to one rule: branch off main for anything you're working on, open a pull request when ready, and merge back into main once it's reviewed -- simple enough for teams that deploy continuously rather than on a fixed schedule.
Example: GitHub Flow
git checkout main
git checkout -b add-search-bar
# open a pull request, review, then merge into main
GitLab Flow
GitLab Flow adds environment branches (like staging and production) alongside feature branches, so code visibly progresses through each environment as it's promoted -- giving you an audit trail of exactly what's deployed where.
Example: GitLab Flow
git checkout -b staging main
git checkout -b production staging
Trunk-Based Development
Trunk-Based Development pushes simplicity even further: everyone commits frequently to one shared trunk, often multiple times a day, using very short-lived branches (or none at all) specifically to minimize the pain of large merge conflicts.
Example: Trunk-Based Development
git checkout main
git checkout -b quick-fix
git commit -m "Small change"
git checkout main
git merge quick-fix
Cleaning Stale Branches
Regardless of which strategy you follow, git branch --merged main combined with git branch -d clears out feature branches whose work has already landed on main, keeping the branch list from accumulating clutter as a project grows.
Example: Cleaning Stale Branches
git branch --merged main
git branch -d old-feature
Chapter Quiz — Complete all 9 topics to unlock
0/9 topics done
Complete these topics first: