Getting Started with Git-Flow

What is Git-Flow?

Git-Flow is a branching strategy model that is very used in large projects where several developers are working at the same time. It is also an extension for git to support this new workflow.

How does Git-Flow organize the work?

Git-Flow has two main branches to organize the flow.

  • Master: The main code that is in production.
  • Develop: The branch with the “work in progress”, where the next version of the program is being cooked.

Apart from them, there are several auxiliary branches which are of one of the following types:

  • Feature: Branches for new features. They are always based on develop.
  • Release: When we reach an epic and have enough features and code in develop, we create a release branch out of it to start testing, usually in a pre-production environment. If testing passes, we merge this to master with a new tag. If there is any code in this branch from bugfixes that is not in develop, the branch is also merged into develop when merged into master.
  • Bugfix: They can be based on develop or in a release branch, depending on the stage the bug has been found.
  • Hotfix: They are the same as bugfixes, but for bugs found in production. They are based on master, and when merged, they are merged either to master and develop.
  • Support: Experimental branches to support previous releases. More info in Git-Flow FAQs.
Git-Flow Workflow
Image taken from: https://nvie.com/posts/a-successful-git-branching-model/

How can I install Git-Flow extension?

Windows

Git for Windows includes Git-Flow.

https://gitforwindows.org

Debian Based Linuxes

sudo apt-get install git-flow

For other distributions see here: https://github.com/nvie/gitflow/wiki/Linux

macOS

brew install git-flow

Git-Flow Syntax:

Git-Flow has it’s own syntax to support it’s flow. Basically, each command of Git-Flow is equivalent to several standard git commands.

To view Git-Flow possible subcommands just execute

git flow

To see what a subcommand options are, for example for feature, use the option help

git flow feature heĺp

To enable Git-Flow in a repo (Usually hitting enter to default options in wizard is ok)

git flow init

Features

To start a new feature, named for example FT-001

git flow feature start FT-001

This is the equivalent to doing git checkout -b feature/FT-001 when standing in develop.
You now will be standing at a branch located in feature/FT-001.
You should do the changes as usual, add files and commits with git add and git commit.

When you are ready to push your changes, then execute the Git-Flow push equivalent.

git flow feature publish FT-001

EXTRA! Sorry to interrupt your reading but this is something you have to know before continuing. You can view all of the standard git commands being executed at each Git-Flow commands if adding the option –showcommands at the end of any Git-Flow command.

For example: git flow feature publish FT-001 --showcommands

Let’s go on…

When you are done with this feature, the following order will merge your feature to develop and delete the branch for you.

git flow feature finish FT-001

Releases

To create a release branch, named for example release-1.0

git flow release start release-1.0

But hey! Looks like something went wrong during testing and a bug has been found! So now you will have to create a Bugfix branch based on the release. You will do so with the following command:

git flow bugfix start BUG-001 release/release-1.0

As you can see, the syntax is the same but with an extra parameter indicating the base branch. If no base branch is specified, Bugfix branch will be based on develop, so be careful.

Again after adding your changes, to push

git flow bugfix publish BUG-001

And to merge your changes into the release branch

git flow bugfix finish BUG-001

Now your release branch looks good, so you proceed to merge it to master, tag, merge also the changes that are not in develop into it, and delete the branch, all of that with only

git flow release finish release-1.0

Hotfixes

All seemed to be ok, but don’t sell the skin before you’ve caught the bear! A bug has been found in Production! Now you will have to create a hotfix branch out of master to solve it

git flow hotfix start HF-001 master

Do the changes as usual, and push the changes with

git flow hotfix publish HF-001

And finally, merge the changes into either master and develop, tag the change, and delete the branch

git flow hotfix finish HF-001

And that’s it, a very simple syntax that would save a lot of duplicate lines and complex git usage, combined with a very nice branching strategy. See you next!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x