Now Up To  80% OFF  GitKraken Pro
Upgrade to Save
Search
Close this search box.

Git Blog

Releasing the Power of Git

Gitflow

Article updated September 2020

At Syncfusion, we’ve been developing controls and frameworks for software developers since 2001. Over time, as our product line has expanded—emerging from our first grid control to more than 800 different controls across a variety of platforms—our release management process has become increasingly complex. Fortunately, Git came along and made everything easier.

Git is an open source distributed version control system that is flexible and easy to use for all kinds of teams, no matter how big or small. To adopt Git in everyday development, a model called Gitflow was introduced by Vincent Driessen to help simplify development and release management. This article assumes that you have some prior knowledge of Git and its basic terminologies. It aims to further describe Vincent Driessen’s branching model and how his Gitflow extension can be useful in a release management workflow for enterprises.

You can also check out this video, which explains how Gitflow works in the cross-platform GitKraken Client.

No matter which branching strategy your team relies on for Git, GitKraken Client provides superior repo visualization so you can fully understand your branch structure and commit history.

Workflow Model

Gitflow utilizes the core feature of Git, which is the power of branches. In this model, a repository has two core branches:

  1. Master/Main—This is a highly stable branch that is always production-ready and contains the last release version of source code in production. (For the purposes of this article, we will be referring to this branch as “main”).
  2. Develop—Derived from the main branch, the development branch serves as a branch for integrating different features planned for an upcoming release. This branch may or may not be as stable as the main branch. It is where developers collaborate and merge feature branches.

Note: The previous two branches are the starting points for any project. They are very important and should be protected against accidental deletion until the project is better defined. Only authorized leads or project owners should be given the responsibility to merge changes from other branches—such as the feature branch, which we’ll discuss later—to the develop or main branches.

Apart from those two primary branches, there are other branches in the workflow:

  1. Feature—This derives from the develop branch and is used to develop features.
  2. Release—This also derives from develop branch but is used during releases.
  3. Hotfix—This derives from the main branch and is used to fix a bug in the production branch that was identified after a release.

Diagram Author: Vincent Driessen | Original blog post | License: Creative Commons BY-SA

We will discuss these branches in detail along with the Gitflow extension used to simplify the management of these branches. The commands we use for the Gitflow extension are based on the Windows environment, but other platforms have similar commands. You can check out the Gitflow wiki for complete details regarding supported commands.

Installing a Gitflow Extension

The following simplified steps will get you up and running on Windows, although GitHub also hosts installation instructions for different platforms.

  1. Download and install Git for Windows. By default, it will install in this directory: C:\Program Files\Git.
  2. Next, you need to retrieve three files: exe from the util-linux packagelibintl3.dll, and libiconv2.dll from the dependencies packages (libintl and libiconv). (For ease of installation, we gathered and uploaded all these files here.)
  3. Once you have those three files, copy and paste them to the location where Git is installed in your system (i.e. inside a bin folder at C:\Program Files\Git\bin). 
  1. Next, clone or download this repository: https://github.com/nvie/gitflow.
  2. When done, navigate to the folder named “contrib” (gitflow-develop\contrib).
  3. Open the command prompt in that directory in administration mode and type this command: msysgit-install.cmd "C:\Program Files\Git".
  1. Gitflow will be installed and configured in your system and ready to use. You can test it by typing git flow help in the command prompt.

Note: In the next discussion, we will use a sample GitHub repository and a Gitflow extension to demonstrate branches in a workflow.

Setting up Gitflow in Your Repository

When starting a project, you won’t have any code files. No problem, just create a Git repository with an empty directory. When finished, you can clone your repository in your system. In this example, we are using a sample GitHub repository, but the procedure applies for any Git repository.

  1. Clone the branch in your system using the Windows command prompt:
git clone https://github.com/bharatdwarkani/gitflow-example.git
  1. Switch to the following directory:
cd gitflow-example
  1. Initialize Gitflow in this repository:
git flow init

You will receive a message stating that no branches exist and prompting you to use common branch names. If you don’t want to change the default branch names, press enter to proceed. When finished, you will have a Gitflow extension initialized in your repository.

Note: This process has to be done by every developer for any repository they clone in a system. It is not limited to new repositories; it can be used for existing repositories too.

Main and Develop Branches

The main and develop branches form the base of any repository in Git. The main branch contains a version of the code that is in production, and the develop branch contains a version that is due to be released in an upcoming version. Execute the following commands in the command prompt to check out the main branch in your system.

git checkout main
git push -u origin main

You will be prompted for username and password; enter them to proceed. Next, you will need to push the develop branch to a remote repository (i.e. from your system to sync with GitHub). Since the develop branch is only on your local machine, it has to be moved to a remote repository by executing the following commands.

git checkout develop
git push origin develop

Now you have a repository containing main and develop branches copied from your local machine. This is required only when you first start a project from scratch; otherwise, you could work with one of the following branches.

Feature Branch

The feature branch splits from the develop branch and merges back to the develop branch after a feature is complete. The conventional naming of this branch starts with feature/*. This branch is mostly created and used by developers collaborating with teams. The purpose of the feature branch is to develop small modules of a feature in a project.

You might wonder why developers can’t work directly from the develop branch. Why do they need to branch off to a feature branch? To explain this, consider a scenario where you are developing a feature and management decides to drop that feature, as it is no longer required or there is less feasibility of implementing it.

At that time, if you are working in the develop branch directly, it would create a lot of conflicts and possibly break the existing code. Also, to do this you would need to manually delete or comment out code.

Instead, if you branched off a separate feature branch, you could silently discard and delete that branch without affecting the develop branch. Not only does this help develop features, which require the trial-and-error technique, but by using a separate branch you also get an extra level of stability in the develop branch because code from the feature branch undergoes several levels of code reviews and quality assessment before merging into the develop branch.

The lifetime of a feature branch ends once it merges with the develop branch. If multiple developers or teams are working on the same feature, it’s easier for them to collaborate by working on a common feature branch.

The following steps show how a feature branch can be created and published using the Gitflow extension from a Windows command prompt.

  1. To clone a repository:
git clone https://github.com/bharatdwarkani/gitflow-example.git
cd gitflow-example
git checkout develop
git flow init
  1. To start a feature branch (the name of the feature branch will be the name of the feature; we are using feature1 in this example).
git flow feature start feature1

After execution, the feature1 branch is created, but it exists only on your system and will not be available in the remote GitHub repository. Now you can continue with your development, adding files and modifying the code. When you’re done with the feature, you can commit it to your local system and later push it to the remote repository.

  1. Once done, the status of the changes can be checked for newly added or modified files.
git status
git add .
git commit -am "Your message"
  1. The following commands publish the feature to the remote repository.
git flow publish feature1
git push

If you check in the remote repository, a branch with the name feature/feature1 will be created.

Note: In the command prompt, the name of the branch you use is feature1, but Gitflow adds a naming prefix automatically (feature/branch) as a convention. When specifying a branch name in Git commands, you need to use the full branch name (feature/feature1), but in Gitflow commands the general prefix (feature/) need not be specified.

  1. Once a feature is complete and the code has been reviewed, you can complete your work in a branch by issuing the command below. Upon execution, the code will be merged to the development branch automatically and the feature branch will be deleted from the remote repository.
git flow finish feature1
  1. If you need to delete a branch, you can execute: git branch -d feature/feature1

Note: If multiple developers are coordinating on a feature, they need to follow the previous steps for cloning, with one caveat: One of the developers has to create and publish a feature branch, which might be empty, so that the others can work collaboratively. If a new developer needs to work, he or she can follow the same process by modifying the following command.

git flow feature track feature1 instead of git flow feature start feature1

Apart from this, there is one more branch called bugfixIt has a workflow similar to the feature branch, but it is used to fix a bug. 

Release Branch

The release branch derives from the develop branch and merges back into the develop and main branches after completion of a release. By convention, the naming of this branch starts with release/*. This branch is created and used when features are completed and finalized for a versioned release.

Why can’t we directly release from the develop branch? Because the sole purpose of the release branch is to isolate a version of a release that is final but needs some quality assistance and stability from the upcoming version. If we branch off from the release branch, then other developers who are assigned to develop features for an upcoming release and are not involved in the release stability process can continue to development and merge their features into the develop branch without waiting on or affecting the current release process. The release branch helps isolate the development of an upcoming version and the current release.

The release branch’s lifetime ends when a particular version of a project is released. Once this branch merges into the develop and main branches, it can be deleted. And once you have done this, you can tag a main branch with a particular release version—let’s say v1.0—to create a historical milestone.

The following example explains how a release branch can be created and published using the Gitflow extension from the command prompt.

  1. Start a release branch.
git checkout develop
git pull
git flow release start release1
  1. Commit newly added or modified changes and push to the remote repository.
git add .
git commit -am "Your message"
git flow publish release1
git push
  1. Merge changes to the develop branch.
git checkout develop
git merge release/release1
  1. After a release, merge changes to the main branch.
git checkout release/release1
git pull
git flow release finish release1

-or-

git flow release finish -m "Your message" "release1"
git checkout main
git push --all origin

Hotfix Branch

The hotfix branch is derived from the main branch and merged back after completion to the develop and main branches. By convention, the name of this branch starts with hotfix/*. This branch is created and used after a particular version of the product is released to provide critical bug fixes for the production version.

The reason we do this is because one problem you might face when branching off from the develop branch is that some of your developers would have already started work for the upcoming release while you are in the middle of the current release. Your release would contain the next version of features, which are not finalized, but you only need to provide bug fixes for the current version. Instead of branching off from develop branch, you can branch off from the main branch, as that branch contains only the current version of the code in production. This way, branching off from the main branch will not affect your production or development version of the product.

The hotfix branch can be deleted once a critical fix for the current production version is released and merged with the main and development branches. Once you have done this, you can again tag the main branch with an iterative subversion of the release; let’s say v1.1.

This example shows how the hotfix1 branch can be created and published using the Gitflow extension from a command prompt.

  1. Start a new hotfix branch and commit changes after modifications.
git checkout develop
git flow hotfix start hotfix1
git status
git add .
git commit -am "Your message"
  1. Publish the branch to the remote repository.
  2. git flow publish hotfix1 Merge changes to remote repository.
git flow hotfix finish hotfix1

-or-

git flow hotfix finish -m "Your message" "hotfix1"
git status
git checkout main
git push --all origin

Note: All commands starting with “git flow” are based on the Gitflow extension. Actual Git commands don’t have flow keywords in them. They start only with “git.”

Simplify Gitflow with GitKraken Client

The Gitflow model helps manage and organize a release better by using Gitflow extensions. Thank you, Vincent Driessen, for proposing Gitflow and for providing an extension that helps simplify the management workflow of enterprise-level releases.

If you choose to fully embrace the tenants of Gitflow order, you can use them with the legendary cross-platform GitKraken Client, built to help put Git into human terms so developers can code with more confidence.

Mastering the full functionality of Git takes time, so you’ll probably benefit from books like Git Succinctly and GitHub Succinctly. Also consider checking out GitKraken’s comprehensive library of Git tutorial videos, complete with beginner, intermediate, and advanced Git concepts.

GitKraken Client has evolved to meet new challenges, with advanced features like the GitKraken CLI, a Git-enhanced terminal experience with auto-complete and auto-suggest for Git commands.

Like this post? Share it!

Read More Articles

Make Git Easier, Safer &
More Powerful

with GitKraken
Visual Studio Code is required to install GitLens.

Don’t have Visual Studio Code? Get it now.

Team Collaboration Services

Secure cloud-backed services that span across all products in the DevEx platform to keep your workflows connected across projects, repos, and team members
Launchpad – All your PRs, issues, & tasks in one spot to kick off a focused, unblocked day. Code Suggest – Real code suggestions anywhere in your project, as simple as in Google Docs. Cloud Patches – Speed up PR reviews by enabling early collaboration on work-in-progress. Workspaces – Group & sync repos to simplify multi-repo actions, & get new devs coding faster. DORA Insights – Data-driven code insights to track & improve development velocity. Security & Admin – Easily set up SSO, manage access, & streamline IdP integrations.
winget install gitkraken.cli