Git Flow

Rodrigo Espinosa
December 1, 2014

Common scenarios

Environment Branch
Production Live (master)
Staging Release Candidate (sta)
Development Current Development (dev)

As this is an example, it may differ with reality.

What the product expects from your code

If you are following a scenario similar to the sample one, you probably know that you cannot just introduce new features into master, or release hotfixes in master without merging into staging (or viceversa). That is why we have to follow a series of steps before releasing new features or hotfixes.

Adding a feature

  • Pull dev, start coding and then pushing the branch.
  • From time to time merge staging and deploy.
  • If something is not working on staging, fix it in that branch.
  • If everything under staging is working, merge and push to master, deploy to production.

Bug in production!

  • Move to the master branch, fix it and then… push to master, merge staging and development with master (in order to have those bug-free).

Improving this flow

Since Staging is our server for testing new features… The sta branch is our next to be released or release candidate branch.

Introducing feature flow

  • Create a new branch based on staging.
  • If it is needed for collaboration, push the feature branch to origin.
  • After it is done, merge it to staging.
  • Then, delete the feature branch.

Introducing hotfix flow

  • A hotfix is a fix to be done under production.
  • Create a new branch base on master.
  • Code the fix and the merge it to master and sta.
  • 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.

git-flow

Git flow is an extension of git. It was created to follow these steps in a bliss.

Installing git-flow

In Linux: sudo apt-get install git-flow

In Mac: brew install git-flow

Initialising git-flow in an existing project

Run git flow init in the project.

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

It does not 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>

Conclusion

Using git-flow will not only improve the way you maintain code, it will also help a team to use the same flow and prevent new members to make mistakes while they are learning the flow. Git flow is a convention and can be modified for your needs, just fork it.

Slides at: https://speakerdeck.com/rec/git-flow

Note: This article does not try to cover the basics of git-flow nor being a tutorial for how to use it, instead it is an introduction to the subject and (maybe) a persuasion to use it.

"Git Flow" by Rodrigo Espinosa is licensed under CC BY SA. Source code examples are licensed under MIT.

Photo by sophilabs.

Categorized under talks.

We’d love to work with you.

We treat client projects as if they were our own, understanding the underlying needs and astonishing users with the results.