Better code organisation with Git-Flow

Denny Saviant Mohammad
5 min readNov 7, 2019

--

Nowadays, most programmers have already using git as their tool to get a better control on their source code. Ranging from single developer working on their side projects , or a myriad of programmers , working together to tackle various business challenges by building a large system that works synchronously.

What does git offer as a tool , so that it could be the major choice for most programmers , especially for those who work in a large organisation , where conflicts can definitely arise when some mistakes happen , e.g when u merge a wrong code to the master. What can we do to prevent it ?

do not let this thing happen to you because you accidentally delete your colleague code

Here comes , git-flow , an extension of git , built to make your branching experience much better than it used to be. We should thank Vincent Driessen for his marvellous concept back in 2010 , and still relevant until now.

Initially, git flow create “origin/develop” as another main branch instead of just one “origin/master”. This master branch, is a sacred one, because ONLY the clean code in a production-ready state should be merged and pushed to this branch.

On the other hand , “origin/develop” is the branch where most of the dirty works are done. Once we get the assurance of the successful merge, of the sub branches on this development branch, indicated by its success in testing & reviews, we can finally merge and push it to master for production phase.

master and develop exists in parallel

The sub branches we can use during development or just in case the production need an immediate fix are :

  • Feature Branches
  • Release Branches
  • Hot-fix Branches

technically , each of those are just regular branch, however conceptually they have a specific original branch, merging target , and most important, limited lifetime. Once we finished working on those branch, and we merge it to develop. It will be deleted, so we will have a clean branching tree.

Before we get our hands dirty on git flow, we obviously have to install git flow to our development machine because by default, it is not there. It exists as an extension to the current git installation. You can follow the instructions written here

Once you’ve done , we can finally start integrating git-flow to our repository. How are we going to do that? First , let’s make a new one.

1. make new repository

Fill up the details, and after our repo has been created successfully, we can clone it to our machine for further process

2. Create Repository
3. Get the remote url by copying that url
4. Cloning the remote repository has been successful

For the sake of simplicity, i am going to create a single file and make it as our first commit before git flow

5. First commit before git flow

After our initial commit, we can start initialising our real git flow, by typing this command

git flow init

just leave the questioned as default by pressing enter key.

6. Use git flow init

After finishing the command above, we will be automatically checked out to develop branch. Only by then , we can start developing our features with the help of git flow .

7. Starting new feature development

once you’ve done , as always, add your work to the staging area, commit , and finish your feature by using git flow and push it to the remote as usual.

8. Finishing feature development

After someone finish the first feature . Other team members will have pull and merge the latest develop branch to their local machine, so that the won’t be any rejection / conflict before they merge & commit the feature development which is in their responsibility.

Later on, after a successful merging of features to the develop branch, we can put it to release branch for final reviews , further testing, and clean up before entering production phase.

9. Starting release

QA & reviews has been done, and our next production release is already set.

10. Release to the master branch

We have successfully integrating our local . master branch with our recently developed features. As a final touch, push it to remote repository and your new system is good to go.

11. push to master

So, better code versioning and management for a team of developers. Those two things are enough for me to implement this git flow on daily basis. How about you ?

--

--