How to transition from Gitflow to Trunk-Based development

Transitioning from Gitflow to Trunk-Based Development involves shifting from a multi-branch workflow to a streamlined, single-branch approach focused on continuous integration and rapid iteration. This guide explores the differences between the two workflows, reasons for adopting trunk-based development, practical steps for migration, and considerations for ensuring a smooth transition. Key differences between Gitflow and trunk-based […]
I am a Software Developer with a passion for technical writing and open source contribution. My areas of expertise are full-stack web development and DevOps.

How to transition from Gitflow to Trunk-Based development

Transitioning from Gitflow to Trunk-Based Development involves shifting from a multi-branch workflow to a streamlined, single-branch approach focused on continuous integration and rapid iteration. This guide explores the differences between the two workflows, reasons for adopting trunk-based development, practical steps for migration, and considerations for ensuring a smooth transition.

Key differences between Gitflow and trunk-based development

Gitflow uses multiple branches to manage development, often with long-lived feature branches, a develop branch for staging, and a main branch for releases. It is suited for teams emphasizing stability but can lead to bottlenecks due to frequent merge conflicts and complex release management.

Trunk-Based Development eliminates long-lived branches by having developers commit directly to a single shared branch (trunk). Short-lived feature branches may be used but are merged quickly, promoting rapid feedback and deployment cycles.

Comparison of Workflows

  • Branching: Gitflow uses multiple branches; Trunk-Based development minimizes them.
  • Release Management: Gitflow supports complex release processes; Trunk-Based development favors frequent, incremental releases.
  • Integration: Gitflow requires periodic merges; Trunk-Based development enforces continuous integration.

Reasons for transitioning to trunk-based development

Faster releases and improved DORA metrics

Trunk-Based Development aligns with DevOps Research and Assessment (DORA) metrics, improving deployment frequency and reducing lead time for changes. Teams adopting this workflow often experience higher change success rates and shorter mean time to recovery (MTTR).

Reduced complexity and increased deployment frequency

Eliminating long-lived branches reduces the overhead of managing merges and resolving conflicts. Teams can deploy smaller, incremental changes more frequently, reducing the risk of large-scale failures.

Enhanced collaboration and code quality

A shared trunk fosters team collaboration, streamlining code reviews and reducing merge conflicts. You can work on smaller, more manageable changes, leading to cleaner, and maintainable code.

Compatibility with CI/CD

Trunk-Based development integrates seamlessly with modern CI/CD pipelines, enabling rapid feedback and automated testing, ensuring that code remains in a deployable state at all times.

Transitioning from Gitflow to Trunk-Based Development

Transitioning from Gitflow to Trunk-Based Development involves incremental changes to workflows, tools, and team processes. Below, each step is detailed to ensure a smooth transition, minimizing disruptions while aligning with continuous integration principles.

Gradual workflow transition

To shift from Gitflow’s long-lived branches to a trunk-based model, progressively shorten the lifecycle of feature and release branches. Begin by moving from quarterly merges to monthly, then weekly, and eventually daily merges into the trunk. Ensure this gradual change includes the following steps:

  1. Review your current workflow: Assess how long-lived branches impact deployment speed and collaboration. Identify bottlenecks caused by merge conflicts or outdated codebases.
  2. Shorten development cycles: Introduce stricter limits on branch lifetimes. For instance, feature branches should last no more than a few days.
  3. Improve team feedback loops: Establish automated CI pipelines for instant feedback on integrations, enabling developers to merge frequently.

Teams should adopt trunk commits as the primary workflow within months, accompanied by process adjustments to handle potential friction.

Dynamic CI pipelines

Updating CI/CD pipelines is important when adopting trunk-based development. Normally pipelines often run exhaustive tests for all branches, which is inefficient in a single-branch model. Use dynamic pipelines to execute only necessary tests:

  1. Configure conditional triggers: Use tools like GitHub Actions or GitLab CI to determine which tests to run based on the files changed. For example, changes in frontend code should only trigger frontend tests.
  2. Optimize test dependencies: Group tests into categories (e.g., unit, integration, end-to-end) and execute the minimal set required to validate changes.
  3. Implement parallelization: Enable parallel test execution to reduce overall runtime, especially for larger codebases.

Modern build tools

Build tools like Bazel, Buck2, and Nx simplify builds and ensure modularity, making them ideal for trunk-based development. They support incremental compilation and caching, reducing build times:

  1. Adopt incremental builds: Tools like Bazel only recompile components that changed, avoiding redundant work.
  2. Define clear module boundaries: Organize the codebase into well-defined modules to isolate changes and streamline integration.
  3. Enforce build consistency: Use reproducible builds with strict dependency rules to ensure consistency across environments.

Feature flags for safety

Feature flags allow code to be deployed without activating unfinished features, ensuring safe production rollouts.

  1. Use tools like LaunchDarkly or custom-built systems to manage flags.
  2. Enable features for small user subsets to monitor performance and feedback before broader activation.
  3. Regularly audit and clean up unused flags to prevent technical debt.

Define Code Ownership

Clear code ownership ensures accountability and simplifies the review process in Trunk-Based Development.

  1. Use CODEOWNERS files: Assign specific teams or individuals as owners for different parts of the codebase.
  2. Automate reviewer selection: Integrate ownership rules with your CI pipeline to automatically assign code reviewers based on the changes made.
  3. Document ownership: Use developer portals like Backstage to document and visualize ownership rules across the organization.

Adjust Code Review Processes

Code reviews in Trunk-Based Development must be efficient and focused on small, incremental changes. Service Level Objectives (SLOs) for review timing can improve responsiveness:

  1. Set clear expectations: Define SLOs, such as “review within 4 hours” or “merge within a day,” and communicate them to the team.
  2. Focus on small changes: Encourage developers to submit smaller pull requests for quicker reviews and fewer conflicts.
  3. Automate quality checks: Use tools like linters and static analysis to ensure baseline code quality before human review.

The FlexReview SLO management approach is a great starting point for defining review timelines.

Branch management and versioning

While trunk-based development minimizes branches, short-lived feature branches may still be needed.

  1. Adopt a feature branch policy: Ensure branches are merged into the trunk within 24–48 hours. Use pull requests to maintain traceability.
  2. Tag stable builds: Use lightweight tags to mark stable points in the trunk for production releases.

Integrating Merge Queues

Merge queues streamline the integration of changes into the trunk by enforcing sequential merges and running validations for each update.

  1. Automate integration: Set up a merge queue tool such as Aviator merge queue or a custom solution to manage commits. These tools ensure each change passes all tests and validations before merging.
  2. Enforce trunk stability: Merge queues prevent disruptive changes by integrating updates one at a time, maintaining a stable codebase.
  3. Monitor queue activity: You can use the Aviator dashboard or notifications to track queue status, prioritizing urgent fixes while avoiding bottlenecks.

By incorporating merge queues, teams can eliminate race conditions in merging, reduce manual intervention, and maintain a reliable trunk.

What could go wrong during the transition?

Team members may resist adopting new workflows. Address this by explaining the benefits, providing training, and starting with smaller, pilot teams.

Legacy tools may not support Trunk-Based Development well. Evaluate modern alternatives like Backstage for developer portals or integrate observability tools to monitor service health.

Frequent deployments may introduce new bugs. Mitigate this risk by implementing robust automated testing, feature flags, and rollback mechanisms.

Integrating monitoring and observability

Leverage monitoring tools to track service performance during the transition. Distributed tracing, centralized logging, and dashboards provide real-time insights into system health, helping teams quickly address issues in the trunk-based workflow. 

Conclusion

Transitioning from Gitflow to Trunk-Based Development requires gradual adaptation, updated processes, and modern tools. While the shift can be challenging, the benefits—faster releases, improved collaboration, and alignment with CI/CD—make it worthwhile. By addressing potential challenges and fostering a culture of continuous integration, teams can unlock greater agility and code quality.

aviator releases

Aviator.co | Blog

Subscribe

Be the first to know once we publish a new blog post

Join our Discord

Learn best practices from modern engineering teams

Get a free 30-min consultation with the Aviator team to improve developer experience across your organization.

Powered by WordPress