/ git


This post doesn't try to cover the basics of git-flow nor being a tutorial of how to use it. Instead it's an introduction to the subject and (maybe) a persuasion to use it.

To start, let's describe a common scenario:

Production   -> Live                (master)
Staging      -> Release Candidate   (sta)
Development  -> Current Development (dev)

Just so you keep track, you'll read the same titles over and over: how to add a feature and how do a hotfix.

The ugly.


Adding a feature

  1. Pull dev, start coding and then pushing the branch.
  2. From time to time merge staging and deploy.
  3. If something isn't working on staging, fix it in that branch.
  4. If everything under staging is working, merge and push to master, deploy to production.

Bug in production!

  1. Move to the master branch, fix it.
  2. Push to master.
  3. Merge staging and development with master (to have those bug-free).

The good.


Since Staging is our server for testing new features, the sta branch could be considered as our release candidate branch.

Introducing feature flow

  1. Create a new branch based on staging.
  2. If it's needed for collaboration, push the feature branch to origin.
  3. After it's done, merge it to staging.
  4. Then, delete the feature branch.

Introducing hotfix flow

  1. A hotfix is a fix to be done under production.
  2. Create a new branch base on master.
  3. Code the fix and the merge it to master and sta.
  4. After the two merges, delete the hotfix branch.

Until now… If we follow each step, we are using a good workflow.

But the creation, merging and deleting of feature and hotfix branches can be automated.

The better.


Git flow is a git extension. It was created to follow the previous steps in a bliss.

A collection of Git extensions to provide high-level repository operations for Vincent Driessen's branching model.

Installing git-flow

In Linux: sudo apt-get install git-flow

In Mac: brew install git-flow

Initialising git-flow.

You'll notice that git has a new command, you can run git flow to get all the avilable sub-commands.

Run git flow init in the project to activate Git Flow.

This will prompt for the behaviour to follow on creating branches and for determining each branch purpose.

It doesn't matter in which branch are we now, just remember to have the master and sta branches up to date.

Creating a feature with git flow

git flow feature start <FeatureName>
... code a little bit ...
git add .
git commit -m “This is a good commit”
git flow feature finish <FeatureName>

Creating a hotfix using git flow

git flow hotfix start <HotfixName>
... code the fix ...
git add .
git commit -m “This is an awesome fix”
git flow hotfix finish <HotfixName>

Demanding the use of the same flow could prevent common mistakes. Useful for new members while they're getting closer to the project.

Last thing to mention, Git flow is a convention and you can change it for your needs, just fork it.

I gave a talk about this