3 min read

Trunk-Based Development Explained

Trunk-Based Development Explained

Trunk based development is a software development strategy where engineers merge smaller changes into the main codebase. One benefit of this is that it helps avoid any major issues when releasing a software product.

The strategy shifts the focus away from long-lived feature branch development and onto smaller changes, merging single branches into the main codebase. One of the many benefits of this strategy is that it prevents major releases of a software product from having bugs and minimizes merge hell with new code.

Improve Your Devops Collaboration Process

Engineering teams need to be on the same page with code revisions. Source-control systems are a better way for engineers to work together without overwriting each other's changes. The master branch of the code is the main source of development on which other development branches grow. The process of combining revisions makes it easy for developers to quickly identify the most recent version of the code. 

Trunk-based development is collaborative and utilizes short-lived branches for code reviews to ensure high quality and collaboration with development teams. The focus is on building software and integrating practices like feature branches and code reviews. The goal is to create a framework for working together and maintaining a high level of quality and collaboration. 

What Are The Benefits?

The main benefits of trunk-based development are that it allows for continuous integration, consistent code review, and smooth code releases. 

Trunk-based development is an important practice for continuous integration. If you want the benefits of CI, your team needs to make sure to make their builds and tests automated. But if developers work on long, infrequent new branches that are not often integrated into a shared branch, then CI isn't living up to its full potential. 

With trunk-based development, developers are able to easily integrate their code with the main branch. When they finish new work, they merge the changes into the main branch. However, they should not merge to the main branch until they have completed a successful build. 

If you've made changes to your code and another developer has made changes to the same part of it, it can cause a merge conflict. Particularly as teams grow and as the code base scales, these bumps become more difficult to manage. That's because developers will often create separate branches that deviate from the source branch and other developers may be merging code on those branches. Luckily, a trunk-based development process minimizes the number of merge conflicts an engineering team experiences.

Trunk Based Development With Feature Flags

Developers can use feature flags to get feedback on new features before they're launched. As part of the process, developers make code changes in their own branch but don't work it into the main branch yet. After getting feedback and verifying that the new functionality works, the developer can add it to the main branch. 

New features and small changes to the code can be made gradually and safely with feature flags. For instance, companies can use this tool to introduce new features slowly, giving themselves ample time for testing before showing it to end-users.

How Does It Differ From Gitflow?

Gitflow is a versioning system that comes from a different development model. It has more branches and larger commits than traditional Git. Every developer gets their own branch, and they only merge it to the main trunk branch when they're done. This means that there are more branches, but also larger commits. When you use long-lived branches, it requires more work to merge them back into the trunk. When changes are made to this branch, it's more likely that they will conflict with the changes in the main branch. 

Designing a Gitflow system can be a complex process. There are many branches to manage and potentially merge together. One of the main benefits of Gitflow is that it can give you a safety net in case something goes wrong with development, hot-fixes, features, or releases. Since there is more complexity than with other systems, extra planning sessions and team feedback are needed for making new changes. 

Trunk-based development is much simpler than using Gitflow. If you're using trunk-based development, the main branch is assumed to always be stable and ready to deploy. Meanwhile, the traditional method is more complicated because it focuses on fixing one branch while trying to maintain other branches simultaneously. Trunk-based development is easier since it focuses on the main branch as the source of fixes and releases.