Git(Hub) Flow, Trunk Based Development, And Code Reviews
Tags: git, branching, trunkbaseddevelopment, codereview
Published: 2021-06-18 09:07:01

_The right branching model will improve any team’s collaboration, quality, and speed. The wrong model will do exactly the opposite. These are the 3 most used branching models._

Name a company that develops software, there’s a very high chance they’re are using Git to source control their codebase. Actually, there’s a 77% chance, according to [Smartbear’s State of Code Review 2020 Report](https://smartbear.com/resources/ebooks/the-state-of-code-review-2020-report).

There’s also a very high chance this company has a code review process in place. An 84% chance according to [Codegrip’s Code Review Trends in 2020 report](https://www.codegrip.tech/code-review-trends-2020/).

However, there isn’t a single standardized methodology to develop software using Git and Code Reviews because it’s highly dependent on the team and the project characteristics. It’s entirely up to the team to choose which methodology better suits their software development needs and goals.

We’ll go over the 3 main methodologies (also called branching models or branching strategies):

*   Git Flow
*   GitHub Flow
*   Trunk Based Development

### The original: Git Flow

Rarely a blog post has such an impact in the industry as the one Vincent Driessen published on January 05, 2010, named [A successful Git branching model](https://nvie.com/posts/a-successful-git-branching-model/).

In his post, Driessen laid out Git Flow, a robust and strict branching model that became the industry standard for software development for years.

It brought parallel development to the masses, created the perfect conditions for collaborative programming, and it scaled easily.

With it, many companies managed to grow large and efficient teams and to deploy very complex software.

With Git Flow, the repository is centered on the `main` and `develop` branches, and it is supported by `feature-n`, `release`, and `hotfix` branches, as described in this diagram:

![Git Flow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fs3q763bq555zh9u7faq.png)

Code Reviews play an essential part in ensuring the code is up to standard and bug-free when merging `feature` branches to the `develop` branch.

Git Flow allows for a very methodic and orchestrated software development but comes at a very high cost:

*   the sheer volume of branches and its overhead is a nightmare to maintain
*   teams have to be extremely disciplined otherwise they will end up with long-lived branches impossible to merge

### The successor: GitHub Flow

With the advent of web apps and continuous delivery, a lighter and faster branching model gained traction: [GitHub Flow](https://guides.github.com/introduction/flow/). As you might’ve guessed, it was created and popularized by the very own GitHub.

It’s centered on the `main` and `feature` branches. `Main` is always releasable. Developers create a new `feature` branch to make changes. After reviewing these changes for bugs and code quality they will be deployed to production. If they cause problems, a rollback from `main` will take place, otherwise, the `feature` branch is merged to the `main` branch.

![GitHub Flow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhq3wdkpups6brmuq2ub.png)

Compared to Git Flow, GitHub Flow is much lighter. Maintenance is very low because the only long-lived branch is `Main`.

However, GitHub Flow inherits other drawbacks from Git Flow. Undisciplined teams that keep `feature` branches open for weeks risk serious problems when trying to merge. Ultimately, a failed merge can leave `main` undeployable, and that’s a big red flag for continuous delivery.

### The shift: Trunk-Based Development

Also going by TBD, Trunk-Based Development is somewhat famously documented at [trunkbaseddevelopment.com](https://trunkbaseddevelopment.com/). In this branching model, developers make changes directly in a single branch called `trunk`.

`Trunk` is deployable at all times. Changes should be summited daily. Unfinished features should be unexposed with the help of [feature flags](https://martinfowler.com/articles/feature-toggles.html).

![Trunk-Based Development For Smaller Teams](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c7dn60kv59ne02oddsya.png)

Yes, you read it right. It sounds like Yolo Software Development. There are is no code review in TBD, either.
![YOLO merge](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fdvs83gr5f96nd6559cy.png)

The catch is that this method can only work in small teams, with seasoned developers, and pair-programming is highly recommended. The pace is very fast because there is very little, if any, overhead. The team must be very skilled and cautious because everything goes directly to the `trunk`.

This TBD model is actually officially called **Trunk-Based Development For Smaller Teams**. Despite its shortcomings, TBD for Smaller Teams is highly regarded by the software development community for its extremely lightweight workflow.

### The seasoned: Scaled Trunk-Based Development

Luckily TBD has another trick up its sleeve: Scaled Trunk-Based Development. In order to operate at scale, this branching model uses short-lived `feature` branches with a life span of a few days (maximum) before merging to the `trunk`, which is deployable at all times.

Work in progress should be kept to a minimum, not only to avoid merging problems with long-lived `feature` branches, but also to make up for easier and faster code reviews.

Code reviews will guarantee only quality code is merged to the `trunk` and will allow for very early defect detection.

![Scaled Trunk-Based Development](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/se4d7qaizitd1xs3pn6x.png)

With Scale TBD, continuous integration is guaranteed, parallel development is supported, and quality is ensured with simple code reviews. It allows for quicker iterations with fewer errors, and it’s always deployable with very little branch management.

### Own it!

It goes without saying that each team and/or product might warrant different needs in a branching model. Teams should take extra care choosing one.

Whichever branching model is chosen, it is very (!) important that it’s crystal clear to every team member what are the rules and steps in the workflow. Without it, any model will fail to bring out the best of the team and the product.