GitFlow Workflow

Master GitFlow, a powerful workflow for Git that organizes development into semantic branches. Learn installation, initialization, and management of feature and hotfix branches.

GitFlow is a workflow that allows working on separated branches, making it semantically easy to identify what changes are brought by different branches.

Using GitFlow is a way to work optimally on a project, using specific branches for specific kinds of changes. It tells everyone, by the nature of the branch, what kind of work has been achieved through this branch.

Note:

Although GitFlow is just a method to work with Git, a program exists to automate Git usage for the GitFlow workflow, making it much easier to manage branch workflows.

Installation

Windows

Under Windows, Git already contains the GitFlow module, so if you've already installed Git, you can use GitFlow. Otherwise, install Git here.

Mac

To install the GitFlow module under Mac using HomeBrew:

brew install git-flow

Linux

Getting Started

Initialization

To initialize GitFlow, you have to execute the command:

git flow init

This can be run in a folder that can already be a Git repository, or not.

GitFlow Initialization

Note:

It's recommended to name the main branch as main instead of master for modern Git practices.

For the rest, you can set the names that you want, although the default names are preferred to be kept in most cases.

Feature Branches

Feature branches are useful when you have to start new feature development. Although they're just basic branches, they bring semantic information about what changes are made through those branches.

They indicate clearly to everybody that the changes made into them will concern new feature development.

Creation

To create a feature branch, nothing could be easier - just run the command:

git flow feature start <branch_name>

GitFlow Feature

Note:

Equivalent commands without using GitFlow module:

git checkout develop
git checkout -b feature/<branch_name>

Finalization

When your work is done and you want to add it to the develop branch, you just have to do:

git flow feature finish <branch_name>
git pull origin develop

That way, you'll merge the changes you made and pull the changes that others did on the develop branch.

Note:

Equivalent commands without using GitFlow module:

git checkout develop
git merge feature/<branch_name>
git branch -D feature/<branch_name>
git pull origin develop

Hotfix Branches

Hotfix branches have semantic utility too - they're used to bring fixes to features or systems involved in your project. These branches are typically created from the main branch to fix critical issues in production.

Creation

To create a hotfix branch, it's easy - you just have to run:

git flow hotfix start <branch_name>

Note:

Equivalent commands without using GitFlow module:

git checkout main
git checkout -b hotfix/<branch_name>

Finalization

When your work is done, you have to close this branch by running:

git flow hotfix finish <branch_name>

Note:

Important: Hotfix finalization will merge the changes into both main and develop branches to ensure the fix is present in both production and future development.

Equivalent commands without using GitFlow module:

git checkout main
git merge hotfix/<branch_name>
git checkout develop
git merge hotfix/<branch_name>
git branch -D hotfix/<branch_name>

GitFlow Branch Structure

1

Main Branch

Contains production-ready code. Only receives merges from hotfix and release branches.

2

Develop Branch

Contains the latest development changes. Features are merged here and this is where releases are prepared.

3

Feature Branches

Created from develop for new features. Merged back to develop when complete.

4

Hotfix Branches

Created from main for critical fixes. Merged to both main and develop.

Summary

  • GitFlow is a workflow that provides semantic meaning to different branches
  • Installation varies by platform but is available for Windows, Mac, and Linux
  • Initialization with git flow init sets up the branch structure
  • Feature branches are used for new feature development
  • Hotfix branches are used for critical fixes that need to go to production immediately
  • Each branch type has specific creation and finalization commands that automate the underlying Git operations

Note:

GitFlow is particularly useful for larger teams and projects with regular releases. For smaller projects or teams practicing continuous deployment, simpler workflows like GitHub Flow might be more appropriate.