Trunk Based Development

  • Blog /
  • TrunkBasedDev

Trunk Based Development

Trunk Based Development is a branching strategy that operates with no long-running branches. Commits are made directly on main and releases come from builds of main.

Branches

In large teams, short lived branches can be used for managing offline reviews through pull requests etc.

Branches

When using short lived branches, all the ongoining commits to main should be pulled into the branch. To do this never merge, instead rebasing the branch to the new main head, leaving all the branch commits after the main build.

    $ git checkout master
    $ git pull  // get latest from master
    $ git checkout mybranch
    $ git rebase master  // get masters updates and make them the base of my branch
    $ git push --force-with-lease

Another useful technique is to use reset to merge commits to remove any unnecessary noise.

    $ git commit -am "feature x"
    $ git commit -am "fix spelling mistake"
    $ git reset --soft HEAD~2
    $ git commit -am "feature x"
    $ git push --force-with-lease

This branching strategy is often popular among DevOps teams and teams practicing continuous delivery. In fact it is a key enabler of continuous integration and by extension continuous delivery, as teams committing directly to main at least every 24hours is a CI core requirement.

For comparison, an opposing branching stratagy would be GitFlow. This model uses long running feature, release and hotfix branches where your code would not be continuously integrated. It can be challenging for teams and engineers coming from a GitFlow type strategy to shift their way of thinking.

Share:

Image Description

Mark Pollard

I am a technical, delivery and engineering leader / Microsoft technologies technical architect, with a strong passion for software engineering. I am a firm believer in empowered teams with true DevOps cultures. I encourage responsibility over role, high quality and full stack engineers, showing ownership of the software and its behaviour, end to end, from requirements maturing through to its continual and successful running in Production.

All author posts

About

Code Build deploy is a reference site on topics I have found useful, inspired by continuous delivery approaches

Monthly Newsletter

Subscribe to our newsletter and stay up to date with the latest news from mark pollard web!

 

Recent Blog Entries



Contact

Bradford,
West Yorkshire,
United Kingdom

(+44)7912359944