Git & GitHub ยท Chapter 32 of 42

Branching Strategies

A branching strategy defines how a team organizes branches, such as when to create them and how they get merged. Common strategies include Git Flow, GitHub Flow, and trunk-based development.

Choosing a consistent strategy helps teams avoid confusion about where to start new work and how releases are managed, especially as a project and team grow.

Syntax
git switch -c feature/short-lived-task
# work, commit, push, open PR, merge, delete branch

GitHub Flow

GitHub Flow is simple: main is always deployable, new work happens on short-lived feature branches, and every change goes through a pull request before merging into main.

Git Flow and trunk-based development

Git Flow uses separate develop, feature, release, and hotfix branches for more structured releases. Trunk-based development has everyone commit small, frequent changes directly to main or very short-lived branches.

Example 1 (bash)
git switch -c feature/add-search
# ...make changes...
git push -u origin feature/add-search
Output
Branch 'feature/add-search' set up to track remote branch.

Follows GitHub Flow by creating a short-lived branch for one feature, ready for a pull request.

Example 2 (bash)
git branch -d feature/add-search
Output
Deleted branch feature/add-search (was 7f3c2ee).

Deletes the local feature branch after it has been merged, keeping the branch list clean.

Key points

  • A branching strategy defines how a team creates and merges branches.
  • GitHub Flow uses short-lived feature branches merged via pull requests.
  • Git Flow adds structured develop, release, and hotfix branches.
  • Trunk-based development favors small, frequent commits to main.
๐Ÿ’ก Note: Smaller teams and web apps often prefer simple GitHub Flow, while larger projects with scheduled releases may prefer Git Flow.

๐Ÿ“ Quick Quiz

1. What is a branching strategy?

2. In GitHub Flow, what is always true of the main branch?

3. Which strategy uses develop, release, and hotfix branches?