Introduction to Git Flow

Knoldus Inc.
6 min readMay 31, 2021

--

Gitflow is really just an abstract idea of a Git workflow. It is a Git workflow that helps with continuous software development and implementing DevOps practices. It was first published and made popular by Vincent Driessen. The Gitflow Workflow defines a strict branching model designed around the project release. This provides a robust framework for managing larger projects.

Gitflow is ideally suited for projects that have a scheduled release cycle and for the DevOps best practice of continuous delivery. It assigns very specific roles to different branches and defines how and when they should interact. This means it dictates what kind of branches to set up and how to merge them together. It uses individual branches for preparing, maintaining, and recording releases.

How It Works ?

Develop and Master Branches

Instead of a single master branch, this workflow uses two branches to record the history of the project. It is basically based on two main branches with infinite lifetime namely master and develop

  • Master Branch : The master branch contains production code and it stores the official release history.
  • Develop Branch : The develop branch contains pre-production code and serves as an integration branch for features.

It’s also convenient to tag all commits in the master branch with a version number.

Assuming we have a repo setup with a master branch. The first step is to complement the default master with a develop branch. A simple way to do this is for one developer to create an empty develop branch locally and push it to the server. This branch will contain the complete history of the project. Other developers should now clone the central repository and create a tracking branch for develop.

When using the git-flow extension library, executing git flow init on an existing repo will create the develop branch.

Feature Branch

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

Note that feature branches combined with the develop branch is basically Feature Branch Workflow. But, the Gitflow Workflow doesn’t stop there. Feature branches are generally created off to the latest develop branch.

Creating a Feature Branch

  • Without git-flow extensions:
  • git checkout develop
  • git checkout -b feature_branch
  • With git-flow extension:
  • git flow feature start feature_branch

Finishing a Feature Branch

  • Without git-flow extensions:
  • git checkout develop
  • git merge feature_branch
  • With git-flow extensions:
  • git flow feature finish feature_branch

Release Branch

Once develop has acquired enough features for a release (or a predetermined release date is approaching), you fork a release branch off of develop. Creating this branch starts the next release cycle, so no new features can be added after this point — only bug fixes, documentation generation, and other release-oriented tasks should go in this branch.

Release branches support preparation of a new production release. They allow many minor bug to be fixed and preparation of meta-data for a release. May branch off from develop and must merge into master and develop.

Once the release branch is ready to ship, it gets merged into master and tagged with a version number. In addition, it should be merged back into develop, which may have progressed since the release was initiated. 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.

Once the release is ready to ship, it will get merged it into master and develop, then the release branch will be deleted.

Using a dedicated branch to prepare releases makes it possible for one team to polish the current release while another team continues working on features for the next release.

Creating a Release Branch

  • Without the git-flow extensions:
  • git checkout develop
  • git checkout -b release/0.1.0
  • When using the git-flow extensions:
  • $ git flow release start 0.1.0
  • Switched to a new branch ‘release/0.1.0’

Finishing a Release Branch

  • Without git-flow extensions:
  • git checkout master
  • git merge release/0.1.0
  • With git-flow extension:
  • git flow release finish 0.1.0

Hotfix Branch

Maintenance or “hotfix” branches are used to quickly patch production releases. Hotfix branches are necessary to act immediately upon an undesired status of master. Hotfix branches are a lot like release branches and feature branches except they’re 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 (or the current release branch), and master 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 maintenance branches as ad hoc release branches that work directly with master.

Creating a Hotfix Branch

  • Without git-flow extensions:
  • git checkout master
  • git checkout -b hotfix_branch
  • With git-flow extensions:
  • $ git flow hotfix start hotfix_branch

Finishing a Hotfix Branch

  • Without git-flow extensions:
  • git checkout master
  • git merge hotfix_branch
  • git checkout develop
  • git merge hotfix_branch
  • With git-flow extension:
  • git branch -D hotfix_branch
  • $ git flow hotfix finish hotfix_branch

Advantages of GitFlow

Now let’s talk about major advantages provided by Git flow, well we already covered these advantages but let’s summarize them.

  • Ensures a clean state of branches at any given moment in the life cycle of project
  • The branches naming follows a systematic pattern making it easier to comprehend
  • It has extensions and support on most used git tools
  • It is ideal when there it needs to be multiple version in production

Disadvantages of GitFlow

Well nothing is ideal, so Git Flow holds some disadvantage as well like,

  • The Git history becomes unreadable
  • The master/develop split is considered redundant and makes the Continuous Delivery and the Continuos Integration harder
  • It isn’t recommended when it need to maintain single version in production

Summary

Here we discussed the Gitflow Workflow. Gitflow is one of many styles of Git workflows you and your team can utilize.

Some key takeaways to know about Gitflow are:

  • The workflow is great for a release-based software workflow.
  • Gitflow offers a dedicated channel for hotfixes to production.

Overall Flow of GitFlow

  • A develop branch is created from master
  • Feature branches are created from develop
  • When a feature is complete it is merged into the develop branch
  • A release branch is created from develop
  • When the release branch is done it is merged into develop and master
  • If an issue in master is detected a hotfix branch is created from master
  • Once the hotfix is complete it is merged to both develop and master

--

--

Knoldus Inc.

Group of smart Engineers with a Product mindset who partner with your business to drive competitive advantage | www.knoldus.com