Trunk Based Development: What Is It, Work Flow, and How to Implement

Hire Remote Developers
Celso Crivelaro
By
Celso Crivelaro
|
Head of Engineering
Linkedin

Table of Contents

Learn more about what trunk-based development is, the work flow, and how to implement it to use for your development team and tech projects.
Published on
July 7, 2023
Updated on
April 11, 2024

When many developers contribute to a codebase, they must carefully manage changes made to the source code over time. Version control management (VCM) practices track and manage the changes made to the code, provide an accurate and complete history of the code changes, and allow multiple developers to work on the same codebase simultaneously.

One popular VCM practice is trunk-based development. This approach helps to minimize the complexity of managing branches and merge conflicts and encourages developers to integrate their changes into the main codebase as frequently as possible.

What Is Trunk-Based Development?

Trunk-based development is a software development practice based on always keeping the main codebase (trunk) in a releasable state. In trunk-based development, developers work directly on the trunk and continuously integrate their code changes. The trunk is the single source of truth for the project, and all developers merge their changes into it as soon as possible.

Trunk-based development is a form of continuous integration that emphasizes the importance of frequently integrating code changes and testing them in a shared environment to detect and resolve integration issues as soon as possible. This approach helps to minimize the risk of integration problems, reduce the time required to release new features, and improve the overall quality of the codebase.

In trunk-based development, long-lived branches are generally discouraged, and developers are encouraged to work on small, focused features that can be integrated into the trunk quickly. As a result, teams can take advantage of the latest code changes and minimize the time required to resolve conflicts between branches.

Trunk-Based Development vs. Feature Branch

Trunk-based and feature branch development are two different software development approaches used to manage and organize code changes in a version control system.

Trunk-based development is a centralized version control approach where all developers share a single codebase and make changes directly to the main line of development. This approach emphasizes a continuous integration and delivery process, where code changes are frequently integrated and tested, and deployed to production as soon as they are ready. The advantage of this approach is that it promotes a fast and efficient development cycle, with minimal overhead and reduced risk of conflicts between branches.

On the other hand, feature branch development is a decentralized version control approach where developers work on isolated branches, branching off from the main codebase to develop and test new features. This approach allows developers to work independently and make changes to the codebase without affecting other developers. However, it can lead to longer development cycles and increased risk of conflicts between branches. The advantage of this approach is that it provides more flexibility and isolation for developers and can be useful in large projects with many contributors and complex codebases.

Ultimately, the choice between trunk-based development and feature branch development will depend on the specific needs of a project and the development team. Both approaches have advantages and disadvantages, and the best method will depend on factors such as the size and complexity of the codebase, the development process, and the number of contributors.

Attributes of Trunk Based Development

Some of the most common attributes of trunk-based development include the following:

  • Continuous Integration: Trunk-based development emphasizes the importance of continuous integration, where developers integrate their code changes into the trunk as frequently as possible.
  • Small, Frequent Changes: Trunk-based development encourages developers to make small, frequent changes rather than significant, infrequent changes. With smaller changes, there's less chance of introducing bugs, and it's easier to identify and resolve conflicts.
  • Automated Testing: Trunk-based development relies on automated testing to ensure that code changes do not break the build or introduce regressions. Developers run automated tests whenever they integrate code changes into the trunk, and they immediately address any failures.
  • Code Review: Trunk-based development typically involves code review, where other developers review and provide feedback on code changes before integrating them into the main codebase. Code reviews improve code quality and catch potential issues before merging.
  • No Long-Lived Branches: Trunk-based development avoids long-lived branches, as these can lead to conflicts and complicate integration. Instead, changes are incorporated into the trunk as soon as they are ready.
  • Fast Feedback: Trunk-based development provides rapid feedback on code changes, as developers run automated tests whenever the trunk changes. Quick feedback identifies and resolves issues quickly, improving development speed and quality.

Trunk-Based Development Pros and Cons

Like any other version control methodology, trunk-based development has pros and cons, including:

Pros:

  • Simplified version control: Having a single main branch makes version control more straightforward and easier to manage.
  • Faster feedback: With trunk-based development, developers can receive quicker feedback on their code changes because of the immediate integration into the main branch.
  • Reduced conflicts: By integrating code changes frequently, developers reduce the likelihood of conflicts between different branches.
  • Continuous integration: Trunk-based development supports continuous integration, which means that developers can automatically build and test their code changes whenever they make changes.

Cons:

  • Increased risk of breaking the build: With trunk-based development, the risk of breaking the build is higher because every change to the trunk is applied immediately.
  • Lack of isolation: Without feature branches, it can be difficult to isolate changes and test them thoroughly before integrating them into the main codebase.
  • Dependency management: Trunk-based development can make dependency management more challenging, as developers can't separate different components or features easily.
  • Difficulties in releasing: With trunk-based development, maintaining different codebase versions can be challenging.

Trunk Based Development Workflow

A sample trunk-based development workflow might include the following steps:

  1. Code changes: A developer makes changes to the code in a separate branch, usually forked from the main trunk.
  2. Pull request: The developer submits a pull request to the main trunk, requesting that their changes be merged. The pull request contains a description of the changes, the code changes themselves, and any relevant information for reviewing and testing the changes.
  3. Code review: Other developers, typically peers, review the code changes in the pull request. They may ask questions, suggest changes, or provide feedback on the design and implementation of the changes.
  4. Automated testing: The pull request triggers automated tests, such as unit tests and integration tests, to run. These tests help to ensure that the changes do not break existing functionality and meet the required quality standards.
  5. Merging: Once the code review and automated testing are complete and all issues have been addressed, the changes can be merged into the main trunk.

How To Implement Trunk-Based Development

Best practices for implementing a trunk-based development workflow include:

Break Work Into Small Batches

  • Breaking work into small batches ensures that changes are integrated into the trunk frequently and that the codebase remains stable and working.
  • Small batches also help to reduce the risk of conflicts and integration problems, as more minor changes are easier to merge and test.
  • To encourage developers to work on manageable projects, you can use agile methodologies, such as Scrum or Kanban, to help prioritize work and set achievable goals for each sprint or iteration.

Avoid Code Freezes

  • Code freezes can slow development and lead to integration problems, as changes made in isolation may not work well together when pushed into the trunk.
  • To avoid code freezes, you can encourage developers to integrate their changes into the trunk as soon as they are ready, even if they are not yet complete. Quick integration helps avoid error build-ups that can happen when you wait longer.
  • If necessary, you can use feature toggles or branch by abstraction to temporarily hide incomplete features and avoid having them interfere with the rest of the codebase.
  • You can also encourage developers to communicate their plans and progress with each other so that everyone knows what others are working on and when they'll be pushing changes to the codebase.

Test Test Test:

  • Automated testing is an essential part of trunk-based development, as it can catch any code problems before deployment.  
  • Provide your developers with training and support in automated testing procedures. You'll also need to ensure the necessary tools and resources are available.
  • Use continuous integration tools to automatically build and test the code in the trunk, providing quick feedback on any issues. For example, if a change causes a test to fail, the continuous integration tools can alert the developers and help them to identify and fix the issue.
  • Code review tools help developers test and review code changes before pushing them into the trunk. Developers will find issues early in the development process to ensure high-quality code.

Help Your DevOps Team With Control Management

Trunk-based development is valuable for software development teams that prioritize collaboration, speed, and code quality. It can result in a faster and more efficient development process but requires strict adherence to specific practices and procedures to be successful.

Implementing trunk-based development can make it easier for remote teams to collaborate effectively. If you're looking to expand your remote team with developers who are skilled in trunk-based development, Revelo can help. Revelo is an end-to-end talent management platform that simplifies hiring and managing remote teams. We match you with a pool of highly qualified, vetted developers. You choose the best match for your team, and we take care of onboarding, payroll, taxes, and more. Reach out today to find your next developer.

Need to source and hire remote software developers?

Get matched with vetted candidates within 3 days.

Related blog posts

12 Most Popular Programming Languages

Most Popular Programming Languages

Rafael Timbó
READING TIME: 
Software Development
Code Reviews For Remote Teams: Processes, Tools, And Best Practices

Code Reviews For Remote Teams: Processes, Tools, and Best Practices

Lachlan de Crespigny
READING TIME: 
Tech Team Management
Python vs. Java: Differences and Performance Comparison

Python vs. Java

Celso Crivelaro
READING TIME: 
Software Development

Subscribe to the Revelo Newsletter

Get the best insights on remote work, hiring, and engineering management in your inbox.

Subscribe and be the first to hear about our new products, exclusive content, and more.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Hire Developers