Everything You Need to Know About GitFlow

78 VIEWS

·

GitFlow is a branching model for Git made by Vincent Driessen. In this post I will dig into why and how to use GitFlow.

First lets look at the model. A diagram of the model is shown below:

There are a few branching models out there for Git, and GitFlow has some similarities with them, such as using a central repository as the main communication between developers, and having developers work locally, then push branches to the central repo. The main difference between GitFlow and other models is the structure of the branches.

GitFlow considered harmful” might be something you’ve seen before

It seems that GitFlow has been a pretty popular workflow since Driessen’s first article, but with its popularity, there is also some controversy over if the model is as great as people say it is. While I’m not nearly qualified enough to tell you whether it is something you want to use for your next project or not, I’ll go over the positives and negatives, and how to implement it.

How is GitFlow implemented?

To start, GitFlow uses two main branches to keep track of a project: Master and Develop. Master is the branch for official releases and is production ready, and Develop is an integration branch for features to be pushed to. It’s recommended to tag commits in the Master branch with the version number. Depending on the size of your team and the project, it can be difficult to search through the development history with this setup. A benefit of this setup is that all new completed development gets merged back into the Develop branch, which is holding all the features that haven’t been released yet. So when the next release is branched off of Develop, it will automatically contain all of the new stuff that has been finished.

Besides the Master and Develop branches, GitFlow uses supporting branches, one of which being feature branches. Feature branches are exactly how they sound: a branch holding one new feature. When a feature is done, it’s merged into its parent branch: Develop. If you are familiar with the Feature Branch workflow, this part probably sounds the same, which it is. But there’s more.

As soon as the Develop branch has enough features, or a release date is coming up, a release branch is forked from the Develop branch. The Release branch is for no new features, only last-minute fixes and bugs (which we all love), and this also leaves the Develop branch ready to receive features for the next release. (So no one ever has no work to do.) Once the Release branch is ready to ship, it’s merged with the Master (as well as Develop to keep it up-to-date) and tagged with a version number.

Finally, there are Hotfix branches for maintenance. These branches are solely for quickly fixing production releases. This is the only branch that is forked directly off of the Master, then once fixed, is merged back to Master and Develop. (And don’t forget to tag with an updated version number.)

TL;DR

The key benefits of GitFlow are:

  1. Parallel development
  2. Easy collaboration
  3. Support for quick fixes

Some downsides of GitFlow are:

  1. Not ideal for continuous deployment models
  2. Can make project history hard to read
  3. Is slightly complex, and takes time to adjust to

Of course, this is not the only branching model out there, and if you find this flow doesn’t work for you, you have options—Although this can be a wonderful option for traditional release style development.

Sources and more information:
https://www.atlassian.com/git/tutorials/comparing-workflows#gitflow-workflow
https://datasift.github.io/gitflow/IntroducingGitFlow.html
http://nvie.com/posts/a-successful-git-branching-model/
https://danielkummer.github.io/git-flow-cheatsheet/

Do you think you can beat this Sweet post?

If so, you may have what it takes to become a Sweetcode contributor... Learn More.

Samantha has a background in visual and UX design, and is currently studying software engineering at Holberton School. In her (very little) free time she enjoys photography, writing, hiking, learning new things, and making all things pretty. Follow her on twitter @SamScislowicz


Discussion

Click on a tab to select how you'd like to leave your comment

Leave a Comment

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

Menu