Git Flow is a specific branching system for Git. It helps the team to better control and add different project versions. Learn how to use it!
What Is a Git Flow
Git Flow is one of many styles of Git workflows - a branching model set for Git. It is a huge framework for large projects and it can be utilized for your team’s needs. Git Flow describes the project’s release cycle and adds specific roles to different branches. It defines when and how are the branches interacting with each other. In this model, there are two types of branches: Master and Develop. Develop is an integration branch for features. Master stores the official release history. This branching design was published by Vincent Driessen in 2009 and became very popular ever since.
Source: A successful Git branching model
The main branches:
- Master branch stores the official release history. It contains an abridged version of your project. It is the core of the branching model with an infinite lifetime.
- Develop branch is an integration branch for features. It contains the complete history of your project. It also has an infinite lifetime. When the code in this branch is stable and ready for a release, the changes are merged to the master branch and tagged with a release number.
- Feature branches are created for each new feature. Their parent branch is the develop branch. Features should never interact directly with the master branch.
- Release branch is created when there are enough features for a release. It enables one team to work on a current release while another team keeps working on features for the next release. Release branches’ parent is also the develop branch. This branch is where continuous delivery happens.
- Hotfix branches are maintenance branches. They are created to quickly patch production release. These branches enable the team to fix mistakes without interrupting the workflow or waiting for the next release. Their parent is the master branch. Hotfix branches are the only branches to be forked directly off of the master branch. You can automatize the hotfix branch creation: whenever a mistake appears, the hotfix branch is automatically created.
Why You Might Want to Use the Git Flow
- Git Flow Workflow simplifies parallel development because it isolates the new development from the released project. You can work on any project version. The new development is done in feature branches so it is merged back when the developer is satisfied with the code.
- Your team can collaborate better and spends less time managing the project versions if they use simple and clear branching strategy, such as Git Flow Workflow.
- You can always commit the changes and create a new feature branch when you need to interrupt your work. You can come back to your feature at any time.
- Hotfix branches allow your team to make emergency changes. You do not have to worry that you would accidentally merge in a new development at the same time.
Problems the Git Flow Solves
How to Implement the Git Flow
There are lots of different applications that support Git Flow branching model and have specific feature settings for Git Flow (such as SourceTree, SmartGit or GitKraken). Pick the application suitable for your operation system to initialize the Git Flow.
Customize your project setup by following these steps:
- Start using git-flow by cloning an existing git repository.
- Create an empty develop branch to complement the default master branch. Push it to the server.
- Development of new features starts from the develop branch. Each feature resides in its own branch. Push the feature branches to the git repository for backup.
- Merge the feature branch back into develop branch when the feature is finished.
- Create a release branch when the features are ready for a release. The parent is the develop branch.
- Merge the release branch into the master branch and tag it with a version number. After that, it is merged back into the develop branch so the progress since the release is saved. The release branch will be deleted.
- If you need to make some critical changes, create a hotfix branch. Fork the branch directly off of the master branch. When you are finished with the changes, merge the hotfix branch to both master and develop branch (or the current release branch). Tag the master branch with an updated version number.
Common Pitfalls of the Git Flow
- Not every team member uses Git Flow Workflow. It is crucial for smooth project development to ensure that all the team understands and uses the same workflow.
- The Git Flow Workflow is customized for a specific product. The setting is too complicated for a new developer.
- The team has too many features and is unable to finish them before the release. Development is drifting away from production.
Resources for the Git Flow
Want to write for DXKB?
Feel free to contribute. People from DXKB community will be more than happy.
Code Review is an important practice for checking each other's code. The reviewers are other developers from the team. The goal is to uncover potential mistakes that could slip through testing.Read more
Git is a distributed version control system (VCS) tool used for tracking source code during development. Utilizing Git improves collboration among fellow developers.Read more
Code Coverage measures the percentage of source code lines that are covered by automated tests. If you have 90% CC, it means that 10% of the source code is not being tested at the moment.Read more
Continuous Integration is a software development practice that makes developers integrate code changes into a shared repository routinely and frequently. Usually, each person integrates at least daily and that ensures them that their code changes do not break anything.Read more
Practicing Continuous Delivery means that you adopt practices to be ready to release product changes any time you want. Your product is always ready to deploy to production.Read more