Trunk Based Development
Trunk-Based Development plays a vital role in facilitating Continuous Integration and, consequently, Continuous Delivery. When team members commit their changes to the trunk several times a day, it becomes effortless to meet the fundamental requirement of Continuous Integration, which mandates all team members to commit to the trunk at least once every 24 hours. This practice guarantees that the codebase is perpetually deployable and supports the realisation of Continuous Delivery.
Trunk-Based Development eschews the use of long-lived feature branches because they create a significant overhead in terms of code integration and conflict resolution. Long-lived branches can cause code to diverge significantly from the mainline, leading to complex merges and delayed feedback, which are antithetical to the goals of Continuous Integration and Delivery. Instead, feature toggles or feature flags are recommended as an alternative technique to manage changes incrementally without introducing long-lived branches. Feature toggles allow teams to ship changes incrementally while keeping the codebase in a deployable state, without branching, while feature flags provide a way to control the release of features in production. These techniques enable teams to deliver changes more frequently, with less risk and more confidence.
An additional alternative technique to long-lived feature branches in Trunk-Based Development is the use of " branch-by-abstraction." This technique involves using abstractions to separate changes from the codebase without creating long-lived branches. Instead of creating a long-lived branch for a new feature, developers add an abstraction layer that allows the new functionality to coexist with the existing codebase. This abstraction layer can be used to gradually replace the old code, eventually leading to the removal of the abstraction and the full integration of the new feature into the trunk. The branch-by-abstraction technique allows teams to maintain a deployable codebase without creating long-lived branches, and also provides the flexibility to change direction or revert changes quickly if necessary.