Lesson 06

GitFlow Branching

A structured branching model for predictable, parallel development

Branching Strategy Feature Branches Release Management Hotfixes Conventional Commits Merge Strategies

Why Branching Strategy Matters

Without a branching strategy, teams stumble over each other. Code gets lost, deployments break, and nobody knows what is in production. A well-defined branching model gives you:

💡 Key Insight

GitFlow is not the only branching model (trunk-based development is popular for CI/CD-heavy teams), but it excels when you need structured releases and multiple parallel streams of work.

The Five Branch Types

GitFlow defines five distinct branch types, each with a clear purpose and lifecycle.

Branch Purpose Created From Merges Into Lifetime
main Production-ready code Permanent
develop Integration branch main Permanent
feature/* New functionality develop develop Short-lived
release/* Release preparation develop main + develop Short-lived
hotfix/* Emergency production fix main main + develop Short-lived

GitFlow Visual Overview

🏷️
main Production-ready, tagged releases
🔀
release/* QA, version bump, changelog
🔗
develop Integration branch
🚧
feature/* Short-lived, one per story
🚑
hotfix/* Emergency fix from main
🏷️
main Merge + tag
🔗
develop Back-merge hotfix
✅ Reading the Diagram

main only receives merges from release and hotfix branches. develop is the central hub where features land. Feature branches are short-lived and merge back into develop via pull requests.

Branch Naming Conventions

Consistent naming makes branches searchable, sortable, and self-documenting.

Pattern: type/TICKET-ID-short-description

# Feature branches
feature/STORY-123-user-authentication
feature/STORY-456-export-csv

# Release branches
release/v1.2.0
release/v2.0.0-beta

# Hotfix branches
hotfix/FIX-789-null-pointer-crash
hotfix/FIX-012-security-patch
⚠️ Naming Rules

Use lowercase, hyphens (not underscores), and keep descriptions under 5 words. Always include the ticket ID so branches are traceable back to your backlog.

The Complete GitFlow Workflow

💡 Agile Framework Integration

The agile framework provides commands that follow this branching model. Use /agile-code-branch to create properly named branches and /agile-code-merge to merge with the correct strategy. These commands prompt you for required inputs like branch type, ticket ID, and merge strategy.

Step 1: Create a Feature Branch

git checkout develop
git pull origin develop
git checkout -b feature/STORY-123-add-login

Step 2: Develop and Commit

# Work in small, focused commits
git add src/auth/login.ts
git commit -m "feat(auth): add login form component"

git add src/auth/login.test.ts
git commit -m "test(auth): add login form unit tests"

Step 3: Open a Pull Request into develop

git push origin feature/STORY-123-add-login
# Open PR: feature/STORY-123-add-login → develop
# Get code review, pass CI checks

Step 4: Merge to develop

# Squash merge for a clean history
git checkout develop
git merge --squash feature/STORY-123-add-login
git commit -m "feat(auth): add login form (#123)"
git branch -d feature/STORY-123-add-login

Step 5: Create a Release Branch

git checkout develop
git checkout -b release/v1.2.0
# Bump version, update changelog, final QA

Step 6: Merge Release to main and Tag

git checkout main
git merge --no-ff release/v1.2.0
git tag -a v1.2.0 -m "Release v1.2.0"
git push origin main --tags

# Back-merge to develop
git checkout develop
git merge --no-ff release/v1.2.0
git branch -d release/v1.2.0

Step 7: Hotfix Workflow

# Create hotfix branch from main
git checkout main
git pull origin main
git checkout -b hotfix/FIX-789-null-pointer-crash

# Fix the bug, commit
git add src/auth/session.ts
git commit -m "fix(auth): handle null session on token refresh"

# Merge hotfix into main with --no-ff
git checkout main
git merge --no-ff hotfix/FIX-789-null-pointer-crash
git tag -a v1.2.1 -m "Hotfix v1.2.1"
git push origin main --tags

# Back-merge hotfix into develop with --no-ff
git checkout develop
git merge --no-ff hotfix/FIX-789-null-pointer-crash
git branch -d hotfix/FIX-789-null-pointer-crash
⚠️ Hotfix Merge Strategy

Hotfixes always use --no-ff when merging into both main and develop. Never squash-merge a hotfix — the merge commit preserves traceability and makes the fix visible in the branch history.

Commit Conventions

We follow Conventional Commits to make history readable and enable automated changelogs.

Prefix Purpose Example
feat:New featurefeat(cart): add quantity selector
fix:Bug fixfix(auth): handle expired tokens
refactor:Code restructuring (no behavior change)refactor(api): extract validation middleware
test:Adding or updating teststest(cart): add edge case for empty cart
docs:Documentation changesdocs(readme): update setup instructions
perf:Performance improvementperf(query): add index for user lookup
chore:Build, tooling, dependencieschore(deps): update lodash to 4.17.21
🚫 Critical: Structural vs Behavioral

Never mix structural changes (refactor:, renames, moves) with behavioral changes (feat:, fix:) in the same commit. This makes reverts safe and code review focused.

Merge Strategies

Squash Merge — For Feature Branches

Condenses all feature commits into a single commit on develop. Keeps the integration branch clean and readable.

git merge --squash feature/STORY-123-add-login

Merge Commit (no-ff) — For Releases and Hotfixes

Preserves the branch structure in history. You can always see where a release or hotfix started and ended.

git merge --no-ff release/v1.2.0

Golden Rules

Agile Framework Commands for GitFlow

The agile framework provides commands that implement this branching model. Each command prompts you for the required inputs.

Command GitFlow Step What You Provide
/agile-code-branchCreate feature, release, or hotfix branchBranch type, ticket ID, description
/agile-code-tddDevelop with tests (on feature branch)Feature requirements, test cases
/agile-code-ciVerify CI passes before mergeCI configuration, fix guidance
/agile-code-commitCommit with conventional formatChange description, scope
/agile-code-prOpen pull requestPR description, reviewers
/agile-code-pr-reviewReview the pull requestReview criteria, feedback
/agile-code-mergeMerge with correct strategyTarget branch, merge strategy
/agile-ship-hotfixEmergency hotfix workflowBug description, severity
/agile-ship-releaseRelease branch workflowVersion, changelog entries
/agile-ship-changelogGenerate changelog from commitsVersion range, format

🧠 Knowledge Check

Where do feature branches merge into?