What is Gitflow and Why Should You Know About It?

What is Gitflow and Why Should You Know About It?

Daily short news for you
  • How terrifying, Codeium - known as a competitor to Github Copilot, as it allows users to use it for free without limits. Recently, they introduced the Windsurf Editor - no longer just a VSCode Extension but a full Editor now - directly competing with Cursor. And the main point is that it... is completely free 🫣.

    » Read more
  • There is a rather interesting study that I came across: "Users never bother to read things they don't want to." (That's a bold statement, but it's more true than not. 😅)

    Don't believe it? I bet you've encountered situations where you've clicked on a button repeatedly and it doesn't respond, but in reality, it has displayed an error message somewhere. Or you've filled out everything and then when you hit the submit button, it doesn't go through. Frustrated, you scroll up or down to read and find out... oh, it turns out there's an extra step or two you need to take, right?

    It’s not far from the blog here. I thought that anyone who cares about the blog would click on the "Allow notifications" button just below the post. But the truth is, no one bothers to click it. Is it because they don't want to receive notifications? Probably not! I think it's because they just didn’t read that line.

    The evidence is that only when a notification pops up and takes up half the screen, or suddenly appears to grab attention, do they actually read it—and of course, it attracts a few more subscribers—something that was never achieved before.

    » Read more
  • A short article about the concepts of Functors, Applicatives, and Monads in functional programming that every time I read, I understand a little more 😅

    Functors, Applicatives, And Monads In Pictures

    » Read more

The Problem

Since we often work with Git, it is safe to assume that most people are familiar with Git concepts such as branches and commands like checkout, merge, rebase, and revert.

When developing a new feature, we usually checkout from the current branch to another branch to work on it. In a team environment, multiple people may be developing multiple features, each on their own branch, allowing for independent and parallel development. Everything would be perfect if one day, when merging branches together, there were no conflicts.

Gitflow was created to define rules for branching and feature development, as well as product releases. It is a workflow for working with Git that is most convenient for developers.

What is Gitflow?

Gitflow is a concept that defines branching and coordination for developing and releasing features using Git.

Gitflow can be customized by development teams based on their environment and requirements. It can be either created from scratch or based on an existing workflow.

There are many variations of Gitflow, but the most famous one is based on Vincent Driessen's branching model.

Gitflow based on Vincent Driessen's Branching Model

gitflow Vincent Driessen

In Vincent Driessen's Gitflow, the workflow is as follows:

  • The starting branch is master. When starting development of a new feature, we checkout from master to develop.
  • Each feature is then checked out from develop to branches with the prefix feature/feature-name. For example, a login feature would be feature/login, and a logout feature would be feature/logout. Each feature is developed independently. After completion, the feature branch is merged into develop.
  • During the release cycle, develop is merged into release. The release branch acts as a staging environment for the project. It closely resembles the production environment and only includes bug fixes, not new features. If any bug fixes are needed on the release branch, they are merged back into develop.
  • When all bugs are fixed, the release branch is merged into master. A tag can be added to mark the release for convenient tracking and tracing.
  • In production, bugs are unavoidable. In such cases, we checkout from master to a hotfix/fix-name branch to fix the bug. After fixing the bug, the hotfix branch is merged into develop. Once the fix is verified in develop, it is merged into master, effectively ending the bug fix session.

As you can see, with this Gitflow model, we need at least three environments for running code: production, staging, and develop, corresponding to the master, release, and develop branches, respectively. However, in practice, it is not necessary to have all three environments. We can customize Gitflow to suit our project's needs and optimize it for efficiency.

The Gitflow based on Vincent Driessen's model can be complex and may slow down the development process or result in a high number of code conflicts. However, it provides clear and distinct branches, and it is easy to establish multiple environments (develop, staging, production).

For example, we can have just the develop and production environments but still ensure that feature development branches are checked out from develop and merged into master before going into production.

Apart from the flows mentioned above, there are other Gitflows as well. In fact, both GitHub and Gitlab have proposed Gitflows for working on their platforms. If time allows, I will write another article discussing the Gitflows proposed by these two industry giants.

Conclusion

In this article, I have presented the concept of Gitflow along with the Gitflow model based on Vincent Driessen's branching diagram. Gitflow was created to address the challenges of working in teams by providing a convenient and conflict-free workflow. Gitflow is also a characteristic of a software development team. If you are using any Gitflow, feel free to share it with others!

Premium
Hello

5 profound lessons

Every product comes with stories. The success of others is an inspiration for many to follow. 5 lessons learned have changed me forever. How about you? Click now!

Every product comes with stories. The success of others is an inspiration for many to follow. 5 lessons learned have changed me forever. How about you? Click now!

View all

Subscribe to receive new article notifications

or
* The summary newsletter is sent every 1-2 weeks, cancel anytime.
Author

Hello, my name is Hoai - a developer who tells stories through writing ✍️ and creating products 🚀. With many years of programming experience, I have contributed to various products that bring value to users at my workplace as well as to myself. My hobbies include reading, writing, and researching... I created this blog with the mission of delivering quality articles to the readers of 2coffee.dev.Follow me through these channels LinkedIn, Facebook, Instagram, Telegram.

Did you find this article helpful?
NoYes

Comments (1)

Leave a comment...
Avatar
Nguyễn Văn Nhật2 years ago
Gitflow trên khá rắc rối mà tôi làm ở các công ty thường sẽ có gitflow rút gọn hơn, vấn đề là việc áp dụng mô hình trên khá phức tạp và mọi người có xu hướng làm việc không nghiêm túc hay chỉ thời gian đầu
Reply
Avatar
Nguyễn Văn Nhật2 years ago
Đúng thế như cty mình flow tuỳ dự án bởi không phải maintain nhiều version cùng lúc
Avatar
Tùng Nguyễn2 years ago
Các cty thường sẽ rút ngắn luồng này xuống