Skip to content

Instantly share code, notes, and snippets.

@AppleBoiy
Created July 12, 2024 12:32
Show Gist options
  • Save AppleBoiy/6ae4118d558d1f1d685015fdf3a06339 to your computer and use it in GitHub Desktop.
Save AppleBoiy/6ae4118d558d1f1d685015fdf3a06339 to your computer and use it in GitHub Desktop.
How to trunk-based development: https://cmu.to/eTeKI

Trunk-Based Development

Trunk-based development is a source-control branching model where developers collaborate on code in a single branch called the "trunk" or "mainline." This model emphasizes continuous integration and frequent merging of code changes into the trunk to ensure that the codebase remains in a deployable state.

Image Source: Trunk-Based Development

Key Concepts

  • Single Trunk Branch: All developers work on a single main branch (often called main or trunk).
  • Frequent Commits: Developers commit their code changes frequently, ideally multiple times a day.
  • Short-lived Feature Branches: If feature branches are used, they should be short-lived, typically lasting a few hours to a few days.
  • Continuous Integration (CI) [skipped]: Use CI tools to automatically build and test the code in the trunk to catch issues early.

Benefits

  • Simplifies Merging: Reduces the complexity of merging long-lived branches and resolving conflicts.
  • Improves Code Quality: Continuous integration helps detect and fix bugs early.
  • Faster Releases: Ensures that the codebase is always in a deployable state, enabling frequent and reliable releases.
  • Enhanced Collaboration: Encourages team collaboration as everyone works on the same branch.

Implementation Steps

Image Source: Stanislav Dudkov/LinkedIn

  1. Set Up the Trunk Branch: Designate a branch (e.g., main) as the trunk.
  2. Frequent Integration: Encourage developers to integrate their changes into the trunk frequently.
  3. Automate Testing [skipped]: Use CI/CD pipelines to automate the building, testing, and integration processes.
  4. Code Reviews [skipped]: Implement a code review process to ensure code quality before changes are merged into the trunk.
  5. Feature Toggles: Use feature toggles to manage the deployment of new features without long-lived branches.
  6. Regular Syncs: Developers should regularly sync their local branches with the trunk to stay up-to-date and minimize integration issues.

Best Practices

  • Keep Changes Small: Make small, incremental changes to reduce the risk of integration problems.
  • Test Thoroughly: Ensure comprehensive automated tests cover your codebase.
  • Resolve Conflicts Quickly: Address merge conflicts as soon as they arise to keep the trunk stable.
  • Monitor Build Health: Continuously monitor the build status and address any issues immediately.
  • Communicate: Maintain clear communication among team members to coordinate work and resolve issues promptly.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment