Hendra Nicholas I am a software engineer, consultant and CEO at 41studio currently living in West Java, Indonesia. My interests range from programming to sport. I am also interested in entrepreneurship, technology, and design.

How to Use Git Flow in Your Projects

2 min read

How to Use Git Flow in Your Projects

Git is a version management tool and I am a big fan of it. I am hoping you came here for git flow. So you have basics of git in your hands. Again on the same note of good practices, I think everyone should work on different branches and then keep merging those branches to main branch. But that becomes messy cause generally we forget to create branch. So here is a tool for you.

Note: I am talking about default branches here. You can change that naming convention but I will suggest not to. So coming back to the topic of git flow.


Installing on Mac OS X :

      brew install git-flow

Installing on Ubuntu :

      apt-get install git-flow

Initiating Git flow :

      git flow init

It will promt you something like this :

Branch name for production releases: [master] Branch name for “next release” development: [develop] How to name your supporting branch prefixes? Feature branches? [feature/] Release branches? [release/] Hotfix branches? [hotfix/] Support branches? [support/] Version tag prefix? []

Keep pressing enter key to use the defaults. or just do

      git flow init -d

for accepting all the defaults.

Whats The Whole Process :

  • First I want to be on a development branch and keep working on the various tasks of the projects.

  • For every task of the project we need to create a branch and then merge that branch into develop branch.

  • Once code is production ready. We need to create a release and test the code and make appropriate fixes.

  • Merge the fixed code into development branch and into production branch.

  • Deploy the code and start working on new tasks of the projects.

  • Meanwhile there may be a bug on the production server. We need to fix the code via hotfix and then merge the fixed code on development branch and production branch.

  • Now move back on the task we were actually doing before the hotfix. 😉

  • So now we have git flow ready in our git repository. Lets do things one by one.

Create a New Feature Branch :

For every task we are doing, we will be create a feature using git flow. Lets assume we want to implement login task.

     git flow feature start login

It will create a new branch with feature namespace is feature/login

Now work on this branch and keep commiting your code. Now once done. You want to merge it to develop branch. Here is the command for the same.

     git flow feature finish login

It will merge feature/login branch to develop branch and delete this feature/login branch.

Keep creating new feature branch. Keep working on it. Once done, finish that feature and it will be merge on develop branch. Push that develop branch, so that other people can pull it.

      git push origin develop git pull origin develop

Pushing / pulling a feature.

There may be cases when you need to push feature without merging it develop branch do that this by :

     git flow feature publish name_of_the_feature_like_we_had_login

If you want to pull any feature :

     git flow feature pull origin name_of_the_feature_like_we_had_login

Create a Release and Push The Code to Master Branch (by default master branch is treated as production branch)

Now we have code enough coding. We want to finally test the code and then need to push it on production branch. Lets create a release first so that we can test out the once and make appropriate changes if required.

     git flow release start version_1

Now test the code and make any changes that you need to make. Commit those changes. Once done.

     git flow release finish version_1

This will merge the code into develop branch + master branch and now we can deploy the code from master branch and then come back to develop branch to implement new tasks.

Hot fixes

Now we are working on new cool task and we are on a feature ie my_awesome_task and meanwhile we came to know that there is a bug in the production on the title of the page. Now we need to do a hotfix.

      git flow hotfix start typo_bug_in_title

Now we will fix that title issue and then commit the code and then finish this hotfix.

      git flow hotfix finish typo_bug_in_title

This will merge the code into master branch and into develop branch too. Now you can deploy the code using master branch and come back to your feature my_awesome_task and do the task. You can checkout to your feature branch that you want working on by

      git flow feature checkout my_awesome_task

I hope this make some sense. Let me know if you have any doubts or anything.

Reblogged from www.codebeerstartups.com

Hendra Nicholas I am a software engineer, consultant and CEO at 41studio currently living in West Java, Indonesia. My interests range from programming to sport. I am also interested in entrepreneurship, technology, and design.