Web Tutorials

What are Merging Strategies?

When working with branches, it is likely that you use the command git merge to merge origin/master branches to your local master branch. It’s also likely you don’t know how it works. However, Git interestingly has other ways of merging feature branches to master branches. Merge strategies are different ways of how you can merge a feature branch to your master branch. Each strategy has its own benefits. And in this web tutorial, you will learn the three popular strategies of merging branches together and their differences.

1. Fast Forward

The fast forward strategy is direct and simple. It copies new commits found within origin/master branch to your local master branch. However, this is only acceptable if the origin/master branch is mergeable. Meaning, you are only able to fast forward if the origin/master branch has not been tampered with by other contributors.

If in case the origin/master branch has been tampered with and you want to fast forward merge anyway, Git will configure your local master branch in a chronological order. In other words, each commit will be configured by date. However, this kind of merging is not practical in a sense of clarity and order for the origin/master branch. Each merge should be by feature branch to make the origin/master branch orderly.

In summary, don’t use a fast forward merge if the origin/master branch has been tampered with. Otherwise, you may go ahead and merge.

2. Merge Commit

Merge commit is a merging strategy where the feature branch can clearly be seen within the master branch. In this strategy, you are able to see the commits found in the feature branch unlike the fast forward strategy. Here’s an example:

In a previous tutorial, I have used this same photo to show the workflow of my project. The green line represents the master branch while the other lines not in line with the master branch are considered the feature branches.

Each branch can clearly be seen by the viewers. It also represents one clear commit history of one feature. This makes for a clearer and more orderly manner of viewing the commit history.

3. Squash

Squash merges all commits within the feature branch as one commit. Meaning, in the process of merging the two branches, the squash strategy squashes all of the files within the feature branch to make the entire branch seem as one commit altogether.

Leave a Reply

Your email address will not be published. Required fields are marked *