Learn the Gitflow workflow – in 5 mins or less.

02/09/2018

The Gitflow Workflow defines a strict branching model designed around the project release.
— Atlassian docs

The overall flow of Gitflow

  1. A develop branch is created from master
  2. A release branch is created from develop
  3. Feature branches are created from develop
  4. When a feature is complete it is merged into the develop branch
  5. When the release branch is done it is merged into developand master
  6. If an issue in master is detected a hotfix branch is created from master
  7. Once the hotfix is complete it is merged to both develop and master

Installation

Windows — download here.

Mac*— brew install git-flow

Get started

1) Initialize the gitflow workflow

mkdir gitflow-getstarted
cd gitflow-getstarted
git flow init

*Leave all the prompted options as default when initializing gitflow.

When you do git branch you’ll see two branches initialized — master and develop

The master branch stores the release history, and the develop branch serves as an integration branch for features — meaning all your developers will be creating feature branches from the develop branch.

2) Feature branches

Each new feature resides in its own branch, which can be pushed to the central repository for collaboration. But, instead of branching off of master, feature branches use develop as their base branch. When a feature is complete, it gets merged back into develop. Features should never interact directly with master.

Starting a feature

git flow feature start feature1

Finishing a feature

git flow feature finish feature1

3) Release branches

Using a dedicated branch to prepare releases makes it possible to stabilize the release while continuing on features for the next release.

Once develop has acquired enough features for a release, you create a release branch off of develop. Creating this branch starts the next release cycle, so no new features can be added after this point.

Once the release is ready to ship, it will get merged it into master and develop, then the release branch will be deleted. It’s important to merge back into develop because critical updates may have been added to the release branch and they need to be accessible to new features. If your organization stresses code review, this would be an ideal place for a pull request.

Starting a release branch

git flow release start 0.1.0

Finishing a release branch

git checkout master
git merge release/0.1.0
git flow release finish '0.1.0'
//--you'll enter in the default text editor VIM, nano or something else --
For vim press i to enter insert mode
Type in your message (e.g. v0.1.0)
press ESC, type :wq and hit ENTER

4) Hotfix branches

Maintenance or “hotfix” branches are used to quickly patch production releases. Hotfix branches are like release branches and featurebranches except they are based on master instead of develop. This is the only branch that should fork directly off of master. As soon as the fix is complete, it should be merged into both master and develop (and if one exists, thereleasebranche). Finaly the master branch should be tagged with an updated version number.

Having a dedicated line of development for bug fixes lets your team address issues without interrupting the rest of the workflow or waiting for the next release cycle. You can think of hotfix branches as ad hoc releasebranches that work directly with master.

Starting a hotfix branch

git flow hotfix start hf1

Finishing a hotfix branch

git checkout master 
git merge hotfix/hf1
git flow hotfix finish hf1
//--you'll enter vim or another text editor--
For vim press i to enter insert mode
Type in your message (e.g. v0.1.1)
press ESC, type :wq and hit ENTER

Summary

Gitflow is one of many Git workflows available out there – Gitflow however, in particular, stands out as it’s great for a release-based software workflow.


Leave a Reply

Your email address will not be published. Required fields are marked *