Gated commits are a key technical practice that enables trunk-based development. Gated commits
are a mechanism that ensures that only code that passes certain quality checks and tests can be
committed to the main trunk of the shared codebase. Gated commits prevent broken changes from
affecting other developers or the Continuous Delivery Pipeline. Gated commits typically involve the
following steps:
A developer writes code and runs local tests on their own machine or branch.
The developer pushes the code to a remote repository, where a pre-commit hook triggers a build and
test process on a separate server.
The build and test process verifies that the code meets the quality standards and does not introduce
any errors or conflicts with the existing code on the trunk.
If the build and test process succeeds, the code is automatically merged into the trunk and becomes
available for other developers and downstream activities.
If the build and test process fails, the code is rejected and the developer is notified of the issues that
need to be fixed before retrying the commit.
Gated commits support trunk-based development by ensuring that the trunk is always in a
releasable state, which means that at least once a day, developers must integrate their changes to
the trunk. This is accomplished through short-lived feature branches related to project tasks. Gated
commits reduce the complexity and conflicts of merging long-lived branches, improve the quality
and consistency of the code by enforcing frequent testing and validation, accelerate the delivery and
deployment of new functionality by minimizing the transaction cost and risk, and foster a culture of
collaboration and transparency among developers