DEV Community

Cover image for Gitflow - Introduction
Angel Martinez
Angel Martinez

Posted on

Gitflow - Introduction

What is Gitflow?

Gitflow is a Git Workflow that defines a strict model of branches, mainly oriented to releases, usually for large projects.

It is important to clarify that Gitflow doesn't add new concepts or extra commands. It only assigns specific functions to different branches.

Setting up

Gitflow it's already included by default in Git, so, we can start a new project with Gitflow, put the following command in the terminal:

git flow init -y
Enter fullscreen mode Exit fullscreen mode

The -y flag, basically generate all the branches and prefix for us with the default names. But if you need a some custom prefix or different name of the main branches, you can delete the flag and answer the questions.

The output of this command is the following:

$ git flow init
Initialized empty Git repository in C:/Users/ID139/Desktop/gitflow-practice/.git/    
No branches exist yet. Base branches must be created now.
Branch name for production releases: [master]
Branch name for "next release" development: [develop] 

How to name your supporting branch prefixes?
Feature branches? [feature/] 
Bugfix branches? [bugfix/] 
Release branches? [release/] 
Hotfix branches? [hotfix/] 
Support branches? [support/] 
Version tag prefix? [] 
Hooks and filters directory? [C:/Users/ID139/Desktop/gitflow-practice/.git/hooks] 
$
Enter fullscreen mode Exit fullscreen mode

Well, as we can see, Gitflow creates two branches:

  • master
  • develop

The second thing that Gitflow do, is set the prefix of the other branches like features, hotfix, etc. That's branches look like feature/my_new_feature.

Starting with Gitflow

Like I've told you before, Gitflow has specific functionality for each branch.

Before to start, It's important to say that the develop is basically the full history of our project. The master branch would only be our production branch, this means that all the code in the master branch is functional, documented, and bug-free.

- Feature Branch

Does your project need a new improvement? The feature branch is the one indicated. This branch is based in the develop branch, here we can do the commits of our new functionality.

Start a Feature

With the following command, we can create a new feature branch:

git flow feature start <feature_name>
Enter fullscreen mode Exit fullscreen mode

In <feature_name> you will specify the name for the new Feature. This will basically create the new branch, and assign it as the current or working branch.

At this point, we can start committing the new features for our project.

Publish a Feature

As expected, surely someone works with you in this new Feature, therefore, it's necessary to send it to the main repository, you can do it with:

git flow feature publish <feature_name>
Enter fullscreen mode Exit fullscreen mode

Finish a Feature

At this point, I suppose that your new functionality is finish. The next step is to finish our branch, basically, the feature branch will be merged with the develop branch.

git flow feature finish <feature_name>
Enter fullscreen mode Exit fullscreen mode

Don't forget to do a git pull before finish the feature.

- Release Branch

The release branch, basically allows us to create a "release" of the project, that's mean will be sending our project to a production environment.

Start a Release

To start a new release we need to put the following command in the terminal:

git flow release start <release_name>
Enter fullscreen mode Exit fullscreen mode

The name of your branch is the name that will use the tag of the release.

After this step, you can start to commit your project. In this branch, we're expected to use for documentation and testing.

Publish a Release

Same as above, we can publish our branch if someone needs to collaborate in the branch.

git flow release publish <release_name>
Enter fullscreen mode Exit fullscreen mode

Finish a Release

In this point, all the project works fine. So, we need to finish the release branch.

git flow release finish <release_name>
Enter fullscreen mode Exit fullscreen mode

Don't forget to do a git pull before finish the release.

Unlike other branches, the release branch will be unified with both develop and master. And they will be tagged.

- Hotfix

The hotfix branch helps us to correct errors in production. This is the only branch that derives from the master.

Start a Hotfix

The commands it's the same, but with the corresponding arguments.

git flow hotfix finish <hotfix_name>
Enter fullscreen mode Exit fullscreen mode

Publish a Hotfix

If you need to send it to the main server or repository.

git flow hotfix publish <hotfix_name>
Enter fullscreen mode Exit fullscreen mode

Finish Hotfix

Once the error is corrected, we must end the branch, it will be merged with master and develop. The master branch will be labeled with the version number.

git flow hotfix finish <hotfix_name>
Enter fullscreen mode Exit fullscreen mode

Don't forget to do a git pull before finish the *hotfix *.

Other Branchs

The previous branches are the main ones, or the most common. However, as you could see from the ** log ** when we started a project with git, we have some additional branches.

Which are:

  • Bugfix
  • Support

I hope this guide has helped you to learn a little about Gitflow, a very good tool for working in teams in my opinion. Anything you want to add is welcome.

Reference: Gitflow Workflow

Top comments (0)