Merging

Merging is the action of bringing the changes in one branch onto another branch. In Git there are two types of mergers: fast-forward merges, and three-way merges. To make things clearer, suppose we have a branch called new-feature that we want to merge into master.


Git will use a fast-forward merge if master and new-feature have not diverged. This means that the last common commit for both branches is also the last commit on the master branch. In this case, all Git has to do is move the master pointer to the tip of the new-feature branch.


If the branches have diverged, Git will use a three-way merge. In this scenario, Git will look at three different commits (thus three-way merge). The last common ancestor to both branches and the tip in each branch. Then it will create a new commit (called merge commit) that integrates all changes.