- 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.
In large teams, short lived branches can be used for managing offline reviews through pull requests etc.
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 main
$ git pull // get latest from main
$ git checkout mybranch
$ git rebase main // get mains 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.
Tags:
About the author:
I am a senior software engineering and technical leader / Microsoft technologies technical architect, with a strong passion for continuous delivery. 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 all the way through to its continual and successful running in Production.