DEV Community

Mukumbuta
Mukumbuta

Posted on

How to Use Git-flow in Your Workflow

Hi.
By now, am sure you know there are two principle ways to manage software projects and and optimize a team's workflow in GIT, i.e, Git-Flow and Github Flow, just in case you forgot.
In this article I will dwell on how to use Git-Flow.

Git-flow is simply a git branching model in which instead of having just one main branch, we can have two branches main and development.
That sounds pleasant, Yes?
I know, that's why I should be quick to mention that it has some paticluar use cases. According to luca mezzalira (2014), Git-flow is suggested to be used when your software has the concept of release because it’s not the best decision when you work in Continuous Delivery or Continuous Deployment environment where this concept is missing.

In Git-flow:
main tracks officail release history whereas, development allows for the integration of feature branches.

TIP: Tag all commits to the main branch with version numbers.

First of all one developer creates an empty develope branch and pushes it to the server.

`$ git branch development`
`$ git push -u origin development`
Enter fullscreen mode Exit fullscreen mode

How to make development branch the base branch

To change the base branch from main to devlopement:

  • Head over to github.com
  • On your repository, head over to settings
  • Click on Branches
  • Click on the forward and reverse arrows icon
  • Choose developementin the drop-down menu
  • Select 'I understand...'

Congratulations! You have just changed the base braanch of your respository from main to development

Now, other devs can then clone the central repository and create a tracking branch for development
Instead of branching off of main, feature branches branch off development.
That is to say, development is now the parent of feature branches.
When a feature is complete, the feature branch is merged back into development(This is what is known as 'Feature Branch Workflow').

Spoiler alert: Feature branches must never interact directly with main.

How to create a feature branch

To create a feature branch, head over to your terminal and enter the following commands:

`$ git checkout developement`
`$ git checkout -b feture_branch_name`
Enter fullscreen mode Exit fullscreen mode

Or, you can use the git-flow extention library like so:

`git flow feature start feature_branch_name`
Enter fullscreen mode Exit fullscreen mode

You can then continue with the normal usage of Git.
When dvelopement work on a feature is complete, it's now time to merge feature_branch_name into development like so:

`$ git checkout dvelopement`
`$ git merge feature_branch_name`
Enter fullscreen mode Exit fullscreen mode

Or using the git-flow extention like so:

`$ git flow feature finish feature_branch_name`
Enter fullscreen mode Exit fullscreen mode

Now assuming we have a repository already setup with a main branch, we can demonstrate Feature Branch Flow like so:

`$ git checkout main`
`$ git checkout -b development`
`$ git checkout -b feature_branch_name`
Enter fullscreen mode Exit fullscreen mode

Then run the following commands:

`$ git checkout development`
`$ git merge feature_branch_name`
`$ git checkout main`
`$ git merge development`
`$ git branch -d feature_branch_name`
Enter fullscreen mode Exit fullscreen mode

Release branch

Once development has acquired enough features for a release, we can then fork a release branch off of development.

The beauty of using a dedicated branch to prepare releases makes it possible for one team to polish the current release while another team continues working on features for the next release.

Release branches are based on the development branch. Below are a series of commands for creating a release branch:

Without the git-flow extensions:

`$ git checkout develop`
` $ git checkout -b release/0.1.0`
Enter fullscreen mode Exit fullscreen mode

When using the git-flow extensions:

`$ git flow release start 0.1.0`
Enter fullscreen mode Exit fullscreen mode

You should be able to see some text that goes something like: "Switched to a new branch 'release/0.1.0'"

You can now merge release branch into main and development and delete the branch.

To finish a release branch, use the following methods:

Without the git-flow extensions:

`$ git checkout main`
`$ git merge release/0.1.0`
Enter fullscreen mode Exit fullscreen mode

With the git-flow extension:

`$ git flow release finish '0.1.0'`
Enter fullscreen mode Exit fullscreen mode

That's it!

Top comments (0)