Trunk Based Development

Git avanzato

Amanda Crawford-Adamo

Software and Data Engineer

What is Trunk Based Development?

  • Source control branching CI/CD model
  • Developer no longer push to separate release branches
  • Changes are from short-lived branches pushed to main
  • Small and frequent updates

A graph of commits to main branch and showing branch as release trunk

Git avanzato

Core principles of Trunk Based Development

  1. Frequent commits to main
  2. Short-lived feature branches (< 1 day)
  3. Continuous integration
  4. Feature flags for incomplete work

A depiction of trunk based workflow. Short lived branch includes a feature flag toggle when committing to main.

Git avanzato

Feature flagging in TBD

  • Manages incomplete features
  • Prevent user from being affected
  • Features gradually released

Example Feature Flag Code

  if feature_flag_enabled('new_feature'):
      # New feature code
  else:
      # Old feature code
Git avanzato

Continuous integration in TBD

  • Commits to main trigger automated build and tests
  • Reduce maintenance and faster releases
  • Product alway reliable and stable
  • Ensure secure code and compliance with industry standards
  • Maintain code quality and reduce bug risk
Git avanzato

Benefits and challenges of TBD

Benefits:

  • Reduced merge conflicts
  • Faster release cycles
  • Improved code quality
  • Better collaboration

Challenges:

  • Requires team discipline
  • Needs robust testing
  • Initial learning curve
  • Managing incomplete features
Git avanzato

Best Practices

  1. Commit small changes frequently
  2. Automate testing and deployment
  3. Use feature flags for incomplete work
  4. Conduct regular code reviews
  5. Monitor after deployment
Git avanzato

Let's practice!

Git avanzato

Preparing Video For Download...