Trunk-Based Development

Knowing how to manage the creation of large new features in your repository is an important skill, especially when working in large organizations or on projects with complete CI systems. It can be tempting to have large feature branches with hundreds of new lines of code and it can seem daunting to implement a large feature in small stages. Trunk-based development is a system to handle large changes like this. It focuses on creating small pull requests and using tools such as feature flags. The following article from Atlassian does a great job discussing all the benefits of trunk-based development (i.e. impact on automated testing, having fewer active branches, and more): Atlassian Article

A picture that can help you visualize what trunk-based development might look like on a large team can be found at trunkbaseddevelopment.com

Trunk Based Development Diagram

Feature Flags

As mentioned above, feature flags are a fantastic tool to use when engaging in trunk-based development. The article above explains them abstractly, but a more concrete example might be:

Notice how in the above scenario, if the new feature breaks the deployment, all you have to do is turn your feature flag off again!

Branching By Abstraction

Instead of using feature flags, one can also use the “branch by abstraction” method found in this article. This is similar to referencing an interface instead of a class and much like dependency inversion, can both increase or reduce the complexity of your code. Using the same example by above, you might make a searchAlgorithmInterface, and have both your old and new algorithms implement it.

It is up to the developer which method is better for a given situation.