Git and other version control systems give software developers the power to track, manage, and organize their code.
In particular, Git helps developers collaborate on code with teammates; combining powerful features like commits and branches with specific principles and strategies helps teams organize code and reduce the time needed to manage versioning.
Of course, every developer and development team is different, with unique needs. Here is where a Git branching strategy comes in.
We will be covering three fairly popular Git branch strategies, each with their own benefits. The best part? None of these workflows are set in stone and can, and should, be modified to fit your specific environment and needs.
Please note: many of these original strategies refer to ‘master’ branches, but we have chosen to use ‘main’ instead.
The main idea behind the Git flow branching strategy is to isolate your work into different types of branches. There are five different branch types in total:
The two primary branches in Git flow are main and develop. There are three types of supporting branches with different intended purposes: feature, release, and hotfix.
The Git flow branching strategy comes with many benefits, but does introduce a few challenges.
The Benefits of Git Flow:
The Challenges of Git Flow:
The GitHub flow branching strategy is a relatively simple workflow that allows smaller teams, or web applications/products that don’t require supporting multiple versions, to expedite their work.
In GitHub flow, the main branch contains your production-ready code.
The other branches, feature branches, should contain work on new features and bug fixes and will be merged back into the main branch when the work is finished and properly reviewed.
While working with the GitHub flow branching strategy, there are six principles you should adhere to to ensure you maintain good code.
As with other Git branch strategies, GitHub flow has some highlights and downfalls.
Custom image inspired by the GitHub Flow Guide.
The Benefits of GitHub Flow
The Challenges of GitHub Flow
At its core, the GitLab flow branching strategy is a clearly-defined workflow. While similar to the GitHub flow branch strategy, the main differentiator is the addition of environment branches—ie production and pre-production—or release branches, depending on the situation.
Just as in the other two Git branch strategies, GitLab flow has a main branch that contains code that is ready to be deployed. However, this code is not the source of truth for releases.
In GitLab flow, the feature branch contains work for new features and bug fixes which will be merged back into the main branch when they’re finished, reviewed, and approved.
The GitLab flow branching strategy works with two different types of release cycles:
Custom image inspired by image in GitLab Flow.
Benefits of GitLab Flow
Challenges of GitLab Flow
Ultimately, the answer to which Git branch strategy is the best depends on you and your team’s environment, product and your specific development needs.
There is not a one-size-fits-all Git branch strategy, and regardless of which you end up selecting, it’s likely you can optimize it with further modifications.
The legendary cross-platform Git GUI for Windows, Mac, & Linux helps simplify and visualize Git at a high-level, and supports the Git flow branching strategy. GitKraken integrates with GitHub, GitLab, Bitbucket and Azure DevOps to make it easy to work with hosted repositories. Learn more about how to use GitKraken for a Git flow branching strategy.
Get started with Git flow using GitKraken. Download the GitKraken Git GUI for free.