Gitflow Workflow
Gitflow is a robust branching model designed for projects with scheduled releases. It provides a strict framework for managing features, releases, and hotfixes.
Overview
Gitflow uses multiple long-running branches:
hotfix
↓
main ────●────────────●────────────●────
↑ ↑ ↑
│ │ │
release │ ●──●──┘ │
↑ ↑ │
│ │ │
develop ──●──●───●──●──●────────●───┘
↑ ↑ ↑
│ │ │
feature ●──● ●──●──● │
Branch Types
| Branch | Purpose | Lifetime |
|---|---|---|
main | Production code | Permanent |
develop | Integration branch | Permanent |
feature/* | New features | Temporary |
release/* | Release preparation | Temporary |
hotfix/* | Production fixes | Temporary |
Main Branches
main (or master)
- Always reflects production state
- Only receives merges from
releaseandhotfix - Every merge is tagged with a version
develop
- Main integration branch
- Reflects latest development changes
- Features merge here
- Branches off from
maininitially
Supporting Branches
Feature Branches
Branch from: develop
Merge into: develop
# Create feature branch
git checkout develop
git checkout -b feature/user-profile
# Work on feature
git commit -m "Add profile page"
git commit -m "Add avatar upload"
# Merge back to develop
git checkout develop
git merge --no-ff feature/user-profile
git branch -d feature/user-profile
Release Branches
Branch from: develop
Merge into: develop and main
# Start release
git checkout develop
git checkout -b release/1.2.0
# Only bug fixes allowed here
git commit -m "Fix typo in error message"
git commit -m "Update version number"
# Finish release
git checkout main
git merge --no-ff release/1.2.0
git tag -a v1.2.0 -m "Release 1.2.0"
git checkout develop
git merge --no-ff release/1.2.0
git branch -d release/1.2.0
Hotfix Branches
Branch from: main
Merge into: develop and main
# Start hotfix
git checkout main
git checkout -b hotfix/1.2.1
# Fix the issue
git commit -m "Fix critical security bug"
# Finish hotfix
git checkout main
git merge --no-ff hotfix/1.2.1
git tag -a v1.2.1 -m "Hotfix 1.2.1"
git checkout develop
git merge --no-ff hotfix/1.2.1
git branch -d hotfix/1.2.1
The Complete Flow
Starting a Project
# Initialize with main
git init
git commit --allow-empty -m "Initial commit"
# Create develop from main
git checkout -b develop
git push -u origin develop
Daily Development
1. Create feature branch from develop
2. Develop and commit
3. Merge back to develop
4. Delete feature branch
Preparing a Release
1. Create release branch from develop
2. Bug fixes only (no new features)
3. Update version numbers
4. Merge to main and tag
5. Merge back to develop
6. Delete release branch
Emergency Fix
1. Create hotfix branch from main
2. Fix the issue
3. Merge to main and tag
4. Merge to develop (or current release branch)
5. Delete hotfix branch
git-flow Tool
A tool to simplify Gitflow commands:
Installation
# macOS
brew install git-flow
# Ubuntu
apt-get install git-flow
# Windows
# Comes with Git for Windows
Usage
# Initialize
git flow init
# Feature
git flow feature start user-profile
git flow feature finish user-profile
# Release
git flow release start 1.2.0
git flow release finish 1.2.0
# Hotfix
git flow hotfix start 1.2.1
git flow hotfix finish 1.2.1
Gitflow vs Feature Branch
| Gitflow | Feature Branch |
|---|---|
| Multiple long-running branches | Single main branch |
| Scheduled releases | Continuous deployment |
| More structured | More flexible |
| Release branches for prep | No release branches |
| Complex | Simple |
When to Use Gitflow
Good For
- Products with scheduled releases
- Multiple versions in production
- Dedicated QA/release process
- Enterprise software
- Mobile apps with store reviews
Not Ideal For
- Continuous deployment
- Small teams/projects
- Web apps with frequent deploys
- Projects needing simplicity
Common Challenges
Merge Hell
Long-lived branches can diverge significantly:
Solution: Merge develop into feature branches frequently:
git checkout feature/big-feature
git merge develop
Complex for Small Teams
Full Gitflow might be overkill:
Solution: Simplified Gitflow
- Skip release branches for small releases
- Use main + develop + feature only
Hotfix Conflicts
Hotfix might conflict with current release:
Solution: Merge hotfix into release branch instead of develop if release is active.
Version Tagging
Always tag releases:
# Lightweight tag
git tag v1.2.0
# Annotated tag (recommended)
git tag -a v1.2.0 -m "Release version 1.2.0"
# Push tags
git push origin v1.2.0
# or all tags
git push origin --tags
Summary
- Gitflow uses
main,develop, and supporting branches mainis always production-readydevelopis the integration branch- Features branch from and merge to
develop - Releases prepare code for production
- Hotfixes go directly to
mainand back todevelop - Use
git-flowtools to simplify commands - Best for scheduled releases and complex projects
In the next lesson, we'll explore Trunk-Based Development—a simpler alternative.

