← Back to Git Course | Chapter 3: Branching | Lesson 8 of 9

Git Branch Strategies

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

bash
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

bash
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

bash
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

bash
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

bash
git branch --merged main
git branch -d old-feature

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.