Every Dog has one Blog

How to Use Git Flow in Your Projects

Apr 5th, 2013

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 practicies, 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.

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 appropiate 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.

1

gitflowfeaturestartlogin

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.

1

gitflowfeaturefinishlogin

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.

12

gitpushorigindevelopgitpullorigindevelop

Pushing / pulling a feature.

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

1

gitflowfeaturepublishname_of_the_feature_like_we_had_login

if you want to pull any feature

1

gitflowfeaturepulloriginname_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 appropirate changes if required.

1

gitflowreleasestartversion_1

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

1

gitflowreleasefinishversion_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.

1

gitflowhotfixstarttypo_bug_in_title

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

1

gitflowhotfixfinishtypo_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

1

gitflowfeaturecheckoutmy_awesome_task

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