Git – Should Release Branches Ever Be Merged to Master?

gitrelease-management

My team is using the Git Stable Mainline branching model and we are about to create the first release branch. From what I have read so far, it sounds like release branches are siloed from the master branch and never completely merged back to master. Instead, if a fix is made on the release branch, then it is usually cherry-picked back to the master branch. This makes sense to me since you would want to keep the current release completely separate from development of the next release, while still being able to develop the next set of features on master at the same time as getting the current release ready.

How long should these release branches be kept around for? Are there any cases in which they should be completely merged back into master?

Best Answer

How Long should these branches kept for ?

The first answer that pops in my mind here is :

Why are you creating release branch in the first place ?

If you are aiming to be able to provide support to a version in production use then it should live as long as that version lives with your customers. (say LTS support, you could have multiple such branches, making things a tad bit more complex)

If you are separating stabilisation work from on-going new development then once the version is deployed you don't really need that branch anymore. Here this would hint at a continuous delivery pipeline. Any bugs gets their fix in the next release which would occur as frequently as possible. Some push this to considering the master branch as the stable branch deploying multiple times daily. Others will sync to their sprints and release every two to three weeks.

Should you merge it completely back into master ?

As you guess it all depends on why you adopted this branching strategy. for continuous delivery style, since the branch will never be used again then you should treat it just as you would any feature or bugfix branches, likely you would merge it back to the master and forget about it.

If however you are aiming for LTS style then you likely would not merge it back, especially if you have multiple such branches. Here you would apply the fix to all release branches and cherry pick from one of them to merge that fix back in master. In this scenario the last thing you would want to do is to treat it like any other feature branch where changes from master are pulled up into it and conflicts resolved there rather than in the master.

Without knowing more about your product life-cycle and your team's workflow it is difficult to come up with a more precise advice here.