Git In-depth

Merging and Fast Forward

Nina Zakharenko

Nina Zakharenko

Microsoft
Git In-depth

Check out a free preview of the full Git In-depth course

The "Merging and Fast Forward" Lesson is part of the full, Git In-depth course featured in this preview video. Here's what you'd learn in this lesson:

Nina introduces merging as commits which happen to have more than one parent. Fast-forward occurs when there are no commits on the base branch that happened after the feature branch was created.

Preview
Close

Transcript from the "Merging and Fast Forward" Lesson

[00:00:00]
>> Nina Zakharenko: Under the hood, merge commits are just commits. But they happen to be commits that have more than one parent. I think in most modern Git workflows, most merge commits probably have two parents. But it's entirely possible to have three, four, as many parents as you want getting merged into one commit.

[00:00:24]
It maintains all those same commits that you had created on a future branch. And the merge commit is just a marker of when a new feature was merged into master. So, if we see our commit here, we'll see that it has two parents.
>> Nina Zakharenko: Now, something that I get a lot of questions about in Git is what is fast forwarding?

[00:00:57]
What's a fast forward? Every once in awhile, you check out master. You merge in your feature branch. And if there haven't been any additional changes to master. Git will show you this message saying that it has fast forwarded. This happens when there's a clear path from the tip of the current branch to the tip of the target branch.

[00:01:23]
So in this diagram here, after we branched off feature, there were no more new commits to master. During a fast forward commit, we add the new commits on top of the master branch. And then we just move the master pointer. In this case, we didn't have to make a merge commit.

[00:01:49]
Git knew how to move that pointer automatically. A problem is that during these fast forward commits, if we can possibly lose track of a feature that was merged back into master. Because when you're working on a feature and you merge it back into master. You really wanna have a clear delineator of this was the work that was done in this branch.

[00:02:18]
Otherwise, we might have trouble finding out what feature caused the bug because these commits are just linear. And we will be able to identify which commits had belonged to the feature, if there's no emerge commit.
>> Nina Zakharenko: In order to avoid this, if your workflow needs it. You can specify -- no-ff when doing a merge.

[00:02:49]
This is telling Git that even it can do a fast forward merge, that it shouldn't. We want to retain the history of that merge commit and what this is going to do is force that merge commit when one isn't necessary. So in this case, I'm checking out master, I'm merging in my new feature with the No Fast Forward flag.

[00:03:16]
And what's that done is created a merge commit and moved the master branch.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now