Skip to content

๐ŸŒŠ Git Flow Guide

A comprehensive guide to the Git Flow branching model and workflow


๐Ÿ“š What is Git Flow?

Git Flow is a branching model for Git that provides a robust framework for managing larger projects. Designed by Vincent Driessen in 2010, it defines a strict branching structure built around project releases, providing a structured approach to version control that works well for teams and scheduled release cycles.

๐ŸŽฏ Key Benefits

Benefit Description
๐Ÿ—๏ธ Structure Clear, predefined branching structure
๐Ÿ”„ Parallel Development Multiple features can be developed simultaneously
๐Ÿš€ Release Management Dedicated branches for release preparation
๐Ÿš‘ Emergency Fixes Hotfix mechanism for production issues
๐Ÿงฉ Team Collaboration Facilitates coordination among team members

๐ŸŒฟ Branch Structure

๐Ÿ“Š Core Branches

Git Flow uses two main branches with infinite lifetime:

Branch Icon Purpose Description
main (or master) ๐Ÿญ Production code Contains production-ready code. Every commit represents a release version.
develop ๐Ÿ”จ Development Integration branch for features. Contains the latest delivered development changes.

๐Ÿ”„ Supporting Branches

These branches have a limited lifetime and serve specific purposes:

Branch Type Pattern Source Target Purpose
Feature feature/* develop develop โœจ New features development
Release release/* develop main & develop ๐Ÿ“ฆ Release preparation
Hotfix hotfix/* main main & develop ๐Ÿš‘ Critical production fixes

๐Ÿ”„ Git Flow Workflow Diagram

graph TD
    A[main] -->|"Create hotfix branch"| B[hotfix/1.0.1]
    C[develop] -->|"Create release branch"| D[release/1.0.0]
    C -->|"Create feature branch"| E[feature/new-feature]
    E -->|"Merge when complete"| C
    D -->|"Merge when stable"| A
    D -->|"Merge back"| C
    B -->|"Fix critical bug"| B
    B -->|"Merge fix"| A
    B -->|"Merge back"| C
    A -->|"Tag release"| F[v1.0.0]
    A -->|"Tag hotfix"| G[v1.0.1]

โšก Workflow Processes

๐ŸŒŸ Feature Development

Feature branches are used for developing new features for upcoming releases.

Bash
# ๐Ÿ Start a new feature
git flow feature start new-feature
# Or with standard Git commands:
git checkout -b feature/new-feature develop

# ๐Ÿ’ป Work on the feature, commit changes
git add .
git commit -m "feat: add new feature functionality"

# โœ… Complete the feature
git flow feature finish new-feature
# Or with standard Git commands:
git checkout develop
git merge --no-ff feature/new-feature
git branch -d feature/new-feature
git push origin develop

๐Ÿ“ฆ Release Process

Release branches support preparation of a new production release and allow for minor bug fixes and metadata preparation.

Bash
# ๐Ÿ Start a release
git flow release start 1.0.0
# Or with standard Git commands:
git checkout -b release/1.0.0 develop

# ๐Ÿ”ง Make release adjustments, version bumps, etc.
git add .
git commit -m "chore: bump version to 1.0.0"

# โœ… Complete the release
git flow release finish 1.0.0
# Or with standard Git commands:
git checkout main
git merge --no-ff release/1.0.0
git tag -a v1.0.0 -m "Version 1.0.0"
git checkout develop
git merge --no-ff release/1.0.0
git branch -d release/1.0.0
git push --all && git push --tags

๐Ÿš‘ Hotfix Process

Hotfix branches are used to quickly patch production releases.

Bash
# ๐Ÿ Start a hotfix
git flow hotfix start 1.0.1
# Or with standard Git commands:
git checkout -b hotfix/1.0.1 main

# ๐Ÿ”ง Fix the critical bug
git add .
git commit -m "fix: critical production issue"

# โœ… Complete the hotfix
git flow hotfix finish 1.0.1
# Or with standard Git commands:
git checkout main
git merge --no-ff hotfix/1.0.1
git tag -a v1.0.1 -m "Version 1.0.1"
git checkout develop
git merge --no-ff hotfix/1.0.1
git branch -d hotfix/1.0.1
git push --all && git push --tags

๐Ÿ› ๏ธ Git Flow Tools

๐Ÿงฐ Git Flow Extension

The git-flow extension provides high-level repository operations for Vincent Driessen's branching model.

Bash
# Installation
# On macOS
brew install git-flow

# On Windows (with Chocolatey)
choco install git-flow-winsetup

# On Linux
sudo apt-get install git-flow  # Debian/Ubuntu
sudo yum install gitflow       # CentOS/RHEL

๐Ÿš€ Initializing Git Flow

Bash
# Initialize Git Flow in a repository
git flow init

# You'll be prompted to configure branch naming conventions
# Accept the defaults or customize as needed

๐Ÿ’ก Best Practices

Practice Description
๐Ÿ”’Protect Main Branches Set up branch protection for main and develop
๐Ÿ”Code Reviews Require pull requests and code reviews before merging
๐ŸงชTesting Run tests before completing features, releases, or hotfixes
๐Ÿ“Clear Commit Messages Follow conventional commit format
๐Ÿท๏ธSemantic Versioning Use semantic versioning for releases (MAJOR.MINOR.PATCH)
๐Ÿ“šDocumentation Update documentation with each release
๐Ÿ”„Regular Integration Frequently merge develop into feature branches

โ“ When to Use Git Flow

โœ… Ideal For

  • Teams with scheduled release cycles
  • Projects with multiple versions in production
  • Software that requires formal QA processes
  • Projects with CI/CD pipelines

โš ๏ธ May Be Overkill For

  • Small projects or teams
  • Continuous delivery environments
  • Projects with rapid release cycles
  • Solo developers

๐Ÿ”„ Git Flow vs. Other Workflows

Workflow Best For Key Difference
๐ŸŒŠGit Flow Scheduled releases Structured with multiple branch types
๐Ÿ”„GitHub Flow Continuous deployment Simplified with focus on feature branches
๐ŸฆŠGitLab Flow Environment-based deployment Adds environment branches
๐ŸŒฟTrunk-Based Continuous integration Short-lived branches merged to trunk frequently

๐Ÿ“š Resources

Resource Description
Original Git Flow Post Vincent Driessen's original article introducing Git Flow
Atlassian Git Flow Tutorial Comprehensive explanation with examples
Git Flow Cheatsheet Quick reference for Git Flow commands
Git Flow AVH Edition Enhanced version of the Git Flow extensions
Edraw Git Flow Diagram Visual explanation of the Git Flow model
Dev.to Git Flow Introduction Practical introduction to Git Flow
Git Flow Documentation Official documentation for Git Flow
Atlassian Git Tutorials Comprehensive Git tutorials including Git Flow

๐Ÿ’ก Tip: Consider your project's specific needs when deciding whether to adopt Git Flow. While it provides excellent structure for certain projects, simpler workflows might be more appropriate for others.