Notes
How Git Does Merges
The first thing to understand in this topic is that there are two kinds of merges: fast-forward
and 3-way
.
We will start with the simpler kind of merge: a fast-forward merge.
Fast-Forward
Merge
Fast forward merges are simple. You can think of them as similar to when you are pulling down updates to your repository.
In a fast-forward merge, there is a direct path of commits between the branch you are currently on and the branch that is being merged in. All git does is add all the new commits that were made on the merging branch to the current branch.
3-Way
Merge
When there is not a direct path of commits that were made between the branch you are on and the branch you are trying to merge, git is forced to make a 3-way
merge.
The "3" in the name is there because git is forced to look at 3 different commits to do the merge. Before we go too far though, lets look at how we would get into a situation like that (one where there is no direct path between commits) in the first place.
Imagaine we are on the master
branch and ready to start working on a new new feature. To begin work, we checkout a branch called tim
and start working.
After making several changes, we commit our work. At the same time, however, someone else checked out a new branch named dave
(also from the same commit on master
). Developers on the dave
branch made changes to the same file as on we did, so now there will be conflicts. You can visualize this by looking at the image below:
Now, in order to merge all of our changes together