Unit 5.2 · Tutorial 1

Git Branching Strategies

Chapter 13 · System Design & Deployment
~2.5 hours Intermediate Git · Branching · Git Flow · GitHub Flow

Overview

Version control is essential for collaboration. This tutorial covers the most popular Git branching strategies: Git Flow, GitHub Flow, and others. You'll learn how to structure your branches, manage releases, and collaborate effectively with your team.

Why this matters: A good branching strategy keeps your repository organised, reduces merge conflicts, and enables smooth releases. It's the foundation of team‑based development.

1. Git Basics Review

Git is a distributed version control system. Key concepts:

  • Commit: A snapshot of changes.
  • Branch: A pointer to a commit; enables parallel development.
  • Merge: Combines changes from one branch into another.
  • Rebase: Moves a branch to a new base commit (rewrites history).
# Basic Git commands git init git add . git commit -m "Initial commit" git branch feature/new-feature git checkout feature/new-feature git merge main git rebase main

2. Git Flow

Git Flow is a strict branching model with multiple branch types:

  • main (or master): Production‑ready code.
  • develop: Integration branch for features.
  • feature/*: Features in development (branch from develop).
  • release/*: Release preparation (branch from develop, merge to main and develop).
  • hotfix/*: Emergency fixes (branch from main, merge to main and develop).
# Git Flow commands (using git-flow extension) git flow init git flow feature start new-feature git flow feature finish new-feature git flow release start 1.0.0 git flow release finish 1.0.0 git flow hotfix start critical-bug git flow hotfix finish critical-bug
Pros: Clear structure, good for versioned releases. Cons: Complex, many branches, requires discipline.

3. GitHub Flow

GitHub Flow is a simpler, trunk‑based strategy:

  • main: Always deployable.
  • Feature branches: Branch from main, use pull requests to merge.
  • No release branches or develop branch.
  • Deployments happen from main or via release tags.
# GitHub Flow workflow git checkout -b feature/new-feature # Work on feature git add . git commit -m "Add new feature" git push origin feature/new-feature # Open a pull request # After review, merge to main git checkout main git pull origin main git branch -d feature/new-feature
Pros: Simple, fast, ideal for continuous delivery. Cons: Less structured for complex releases.

4. Other Strategies

  • Trunk‑Based Development: All developers work on a single branch (trunk). Short‑lived feature branches. Good for large teams with CI/CD.
  • Release Branches (without develop): Similar to Git Flow but without a permanent develop branch.
  • Fork‑based workflow: Used in open‑source projects; contributors fork the repo and submit PRs.
# Trunk‑based development # All work on main or short‑lived branches (< 2 days) git checkout -b feature/xyz git add . git commit -m "WIP" git push origin feature/xyz # After review, merge immediately git checkout main git pull git merge feature/xyz git push

5. Choosing a Strategy

Consider these factors:

  • Team size: Small teams → GitHub Flow, large teams → Git Flow or Trunk‑Based.
  • Release frequency: Frequent releases → GitHub Flow, less frequent → Git Flow.
  • Complexity: Simpler is better for most projects.
  • Culture: Some teams prefer strict processes, others prefer flexibility.
// Decision matrix | Factor | Git Flow | GitHub Flow | Trunk‑Based | |-----------------|----------|-------------|-------------| | Complexity | High | Low | Low | | Release mgmt | Good | Moderate | Good | | Team size | Large | Small/Med | Large |

Quiz

Question 1

In Git Flow, which branch is used for preparation of a new release?

  • main
  • develop
  • release/*
  • hotfix/*
Show answer
C. release/*

Question 2

Which branching strategy is recommended for teams practicing continuous delivery?

  • Git Flow
  • GitHub Flow
  • Trunk‑Based Development
  • Both B and C
Show answer
D. Both B (GitHub Flow) and C (Trunk‑Based) support continuous delivery.

Question 3

What is the purpose of a hotfix branch in Git Flow?

  • To add new features
  • To fix critical bugs in production
  • To prepare release documentation
  • To refactor code
Show answer
B. To fix critical bugs in production.

Exercises

Exercise 1

Describe the steps to create a new feature using GitHub Flow. Include branch creation, commits, pull request, and merge.

Sample answer
  1. git checkout -b feature/new-feature
  2. Make changes and commit: git commit -m "..."
  3. Push: git push origin feature/new-feature
  4. Open a pull request on GitHub.
  5. After review, merge the PR into main.
  6. Delete the feature branch.

Exercise 2

Compare Git Flow and GitHub Flow. When would you choose one over the other?

Sample answer

Git Flow: Choose for projects with scheduled releases, complex versioning, and large teams. Provides clear separation of features, releases, and hotfixes.

GitHub Flow: Choose for continuous delivery, small to medium teams, projects with frequent deployments. Simple and fast.

Homework

Homework 1

Choose a branching strategy for your capstone project and write a 200‑word justification. Then create a branch structure diagram showing your branches and their relationships.

Sample outline
  • Strategy: GitHub Flow (simple, continuous integration).
  • Justification: Small team, frequent updates, easy to manage.
  • Diagram: main → feature/* → PR → main.

Mini‑Project

Branching Strategy Workshop

Design a branching strategy for a team of 10 developers working on a financial application with quarterly releases. Create a detailed document that includes:

  • Branch types and their purposes
  • Naming conventions
  • Workflow for features, releases, and hotfixes
  • Merge and deployment process
Sample outline
  • Branch types: main, develop, feature/*, release/*, hotfix/*.
  • Naming: feature/ISSUE-123-short-desc, release/v1.0.0, hotfix/CRITICAL-123.
  • Workflow: Features from develop → PR to develop → release from develop → PR to main and develop → hotfix from main → PR to main and develop.
  • Deployment: main is production, releases are tagged.

Tutorial Summary

You learned the major Git branching strategies, including Git Flow and GitHub Flow, and their trade‑offs. You can now choose the right strategy for your team and project, and implement it effectively.

Key takeaway: A clear branching strategy is essential for team collaboration. Choose a strategy that matches your team's size, release frequency, and complexity.