GitFlow Workflow

Master the GitFlow branching model for structured development

Learning Objectives

  • Understand the GitFlow branching model and its components
  • Learn how to manage feature development using GitFlow
  • Master the release process with GitFlow branches
  • Handle hotfixes effectively using GitFlow conventions

Understanding GitFlow

GitFlow is a branching model that provides a robust framework for managing larger projects. It defines a strict branching model designed around project releases.

Core Concepts

  • Two main branches:main and develop
  • Three supporting branches:feature, release, and hotfix
  • Strict merge rules:Define how branches interact

Benefits

  • Parallel development
  • Structured release process
  • Clear rollback procedures

Main Branches

GitFlow uses two main branches to record the history of the project. The main branch stores the official release history, while the develop branch serves as an integration branch for features.

Main Branch (main)

  • Contains production-ready code
  • All commits tagged with version number
  • Never commit directly to main

Develop Branch

  • Integration branch for features
  • Contains latest delivered development changes
  • Source for feature branches
# Initial setup
$ git flow init
# Configure main branches
$ git checkout main
$ git checkout -b develop
$ git push -u origin develop

Feature Branches

Feature branches are used to develop new features for the upcoming or a distant future release. They exist as long as the feature is in development.

Working with Features

# Start a new feature
$ git flow feature start my-feature
# Work on the feature...
$ git add .
$ git commit -m "Add new functionality"
# Finish the feature
$ git flow feature finish my-feature

Feature Branch Rules

  • Branch from: develop
  • Merge back into: develop
  • Naming: feature/*

Best Practices

  • One feature per branch
  • Regular rebases from develop
  • Clear, descriptive names

Release Branches

Release branches support preparation of a new production release. They allow for minor bug fixes and preparing meta-data for a release.

Managing Releases

# Start a release
$ git flow release start 1.0.0
# Make release preparations...
$ git add .
$ git commit -m "Bump version numbers"
# Finish the release
$ git flow release finish 1.0.0

Release Branch Rules

  • Branch from: develop
  • Merge to: main and develop
  • Naming: release/*

Release Activities

  • Version number bumping
  • Bug fixes only - no new features
  • Documentation updates

Hotfix Branches

Hotfix branches are used to quickly patch production releases. These are similar to release branches but triggered by the need to act immediately upon an undesired state of a live production version.

Working with Hotfixes

# Start a hotfix
$ git flow hotfix start 1.0.1
# Fix the critical bug...
$ git add .
$ git commit -m "Fix critical production issue"
# Finish the hotfix
$ git flow hotfix finish 1.0.1

Hotfix Branch Rules

  • Branch from: main
  • Merge to: main and develop
  • Naming: hotfix/*

Key Considerations

  • Only critical bug fixes
  • Immediate deployment needed
  • Version number must be bumped

GitFlow Commands Summary

Here's a quick reference of common GitFlow commands for different operations:

# Initialize GitFlow
$ git flow init
# Feature branches
$ git flow feature start feature_name
$ git flow feature finish feature_name
$ git flow feature publish feature_name # Share feature
$ git flow feature pull feature_name # Get shared feature
# Release branches
$ git flow release start release_name
$ git flow release finish release_name
$ git flow release publish release_name
# Hotfix branches
$ git flow hotfix start hotfix_name
$ git flow hotfix finish hotfix_name

GitFlow Best Practices

Do's

  • Keep main branch stable at all times
  • Tag all releases in main branch
  • Test thoroughly before merging to develop

Don'ts

  • Add new features in release branches
  • Merge without code review
  • Commit directly to main branch

What's Next?

Now that you understand GitFlow, let's explore how to maintain high-quality commits and documentation. In the next lesson, you'll learn about:

  • Writing effective commit messages
  • Creating atomic commits
  • Managing commit history effectively