For a long time, I thought there was only one way to use Git: having a master branch, a develop branch, story/feature branches, hotfix branches, and release branches. This model is often referred to as Gitflow. However, once I started working and got introduced to trunk-based development, I found it interesting and wanted to write a post about it.
Before diving into trunk-based development, I want to first introduce Gitflow and review some important concepts under this model. The primary components of Gitflow are:
master**branch (aka main branch): This branch keeps track of the release history. In other words, code is only merged into this branch when it is ready to be deployed to production.develop branch: This branch contains new changes being made and is often used for testing in a non-production environment. It ensures that new changes work as expected alongside other people’s changes (assuming multiple developers are working on the same branch).cherry-picking to select features that have been fully tested in develop. Release-related tasks, such as documentation work, can also be added here.develop to contain new changes before they are fully tested.master. After finishing the patch, the hotfix branch is merged back into master. In other words, it functions similarly to a release branch but originates from master instead of develop.develop to create my story branch. After making changes and testing them on my story branch, I open a pull request (PR) to merge it into develop.develop into a non-production environment for acceptance testing, ensuring that no features are broken and that the new feature functions as expected.develop, using the cherry-pick strategy to select my feature along with others being released in this cycle.master and tag it with a version number.develop to ensure the new documentation is included there as well.master to create a hotfix branch. After two hours of battling, we fix the bug, merge the hotfix branch back into master, and deployed to production.develop to ensure the fix is included in ongoing development.