Git

Last Updated: 8/28/2023

Merging

  • Merging is all about bringing changes from one branch to another.
  • Two types of merges
    • Fast-forward merge
    • 3-way merge

Fast-forward merge

  • If the branches have not diverged, and there is a direct linear path from the target branch to the source branch, all git has to do to merge the changes, is to bring the master pointer forward. This is what we call a fast forward merge.

3-way merge

  • If the branches are diverged, when we run a merge, git creates a new commit that combines the changes from these two branches.
  • The reason this is called a three-way merge is because this new commit is based on three different commits the common ancestor of our branches, which includes the before code, and the tips of our branches, which contains the after code.
  • Git looks at three different snapshots, the before snapshot, and after snapshots and based on these, it will figure out how we should combine the changes. So, we create this new commit, which is called a merge commit.