What is the best Git branch strategy?
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.
No matter which branching strategy you choose, GitKraken enables powerful, easier, and safer collaboration with Git with features like predictive merge conflict detection and in-app pull requests.
Git Flow Branch Strategy
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.
Git Flow: Pros & Cons
The Git flow branching strategy comes with many benefits, but does introduce a few challenges.
The Benefits of Git Flow:
- The various types of branches make it easy and intuitive to organize your work.
- The systematic development process allows for efficient testing.
- The use of release branches allows you to easily and continuously support multiple versions of production code.
The Challenges of Git Flow:
- Depending on the complexity of the product, the Git flow model could overcomplicate and slow the development process and release cycle.
- Because of the long development cycle, Git flow is historically not able to support Continuous Delivery or Continuous Integration.
Git Flow with GitKraken
The legendary cross-platform GitKraken Git GUI for Windows, Mac, & Linux helps simplify and visualize Git at a high-level, and supports the Git flow branching strategy.
To initialize Git flow with GitKraken, open your repo and then navigate to Preferences → Gitflow to set your preferred branch naming conventions. GitKraken will then help you start and finish feature, release, and hotfix branches.
GitKraken empowers teams large and small to harness the true power of Git, giving you more visibility into who is working on what and when, so you can avoid conflicts and secure your code.
GitHub Flow Branch Strategy
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.
GitHub Flow Considerations
While working with the GitHub flow branching strategy, there are six principles you should adhere to to ensure you maintain good code.
- Any code in the main branch should be deployable.
- Create new descriptively-named branches off the main branch for new work, such as feature/add-new-payment-types.
- Commit new work to your local branches and regularly push work to the remote.
- To request feedback or help, or when you think your work is ready to merge into the main branch, open a pull request.
- After your work or feature has been reviewed and approved, it can be merged into the main branch.
- Once your work has been merged into the main branch, it should be deployed immediately.
GitHub Flow: Pros & Cons
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
- Of the three Git branch strategies we cover in this post, GitHub flow is the most simple.
- Because of the simplicity of the workflow, this Git branching strategy allows for Continuous Delivery and Continuous Integration.
- This Git branch strategy works great for small teams and web applications.
The Challenges of GitHub Flow
- This Git branch strategy is unable to support multiple versions of code in production at the same time.
- The lack of dedicated development branches makes GitHub flow more susceptible to bugs in production.
GitLab Flow Branch Strategy
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.
Using GitLab flow in your release cycle
The GitLab flow branching strategy works with two different types of release cycles:
- Versioned Release: each release has an associated release branch that is based off the main branch. Bug fixes should be merged into the main branch first, before being cherry-picked into the release branch.
Custom image inspired by image in GitLab Flow.
2. Continuous Release: production branches are utilized to contain deployment-ready code, so code is merged into the production branch when it’s ready to be released.
Benefits of GitLab Flow
- When compared to the Git flow branch strategy, GitLab flow is more simple.
- GitLab flow is more organized and structured than the GitHub flow branch strategy.
- After slight modification, GitLab flow can allow for Continuous Delivery and versioned releases.
Challenges of GitLab Flow
- GitLab flow is not the simplest Git branch strategy.
- GitLab flow is not the most structured Git branching strategy which can lead to messy collaboration.
The ability to visualize your commits and branches will give you and your team a newfound understanding of your repository’s structure, making daily Git actions more intuitive.
So, which is the best Git branching strategy?
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.
Get started with Git flow using GitKraken. Download the GitKraken Git GUI for free.