This blog moved to medium->https://medium.com/@cocoamaemae

Tuesday, May 9, 2017

Best practice when merging multiple git branches


It is general to create multiple branches and manage them parallel when we do the development by using git. Multiple branches should be merged to one branch after the development has done. Here, think about how to merge git multiple branches to one branch finally.

Basic merging way

For example, there would be multiple branches, dev1, dev2 and dev3, which are created from master branch. Have you ever merged them to master branch like Fig.1?

Fig.1


Very simple merging way, so a lot of developers might have merged branches like this. However, this way has a fault. There is a possibility to remove other's modifications.
In Fig.1, dev1 branch is merged at first. So dev2 branch merging may remove dev1 modification, or dev 3 branch merging may remove dev1 or dev2 modifications.

To avoid overwriting to other branch modifications

If you avoid overwriting to other branch modifications, doing like Fig.2 is correct.

Fig.2

















In this way, dev1 modifications are merged to dev2 branch before dev2 branch would be merged. dev1 and dev2 modifications are merged to dev3 branch before dev3 branch would be merged. There is no possibility to remove other modifications.

The rest issues

If we user Fig.2 way, we can avoid overwriting to other branch modifications However, the procedure will be complex. 
So I created gitmumerge which is created by ShellScript, to make Fig.2 procedure automation. It will be introduced in the another post.




No comments:

Post a Comment

Front End Development Tools

TaskRunner Tool executing multiple tasks by only one execution. Tasks are like CSS preprocessor, Transpire, Module Bundler, etc... e.g. ...