AI Hints
Home›Git & GitHub Tutorial›Real Merges
Git & GitHub · Lesson 45 of 144

A Real Merge

When both branches moved.

⏱ 2 min read▶ Video at 48:13🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

A fast forward only works when main hasn't moved. But in real life, main keeps moving, while you work on your branch. Then Git has to truly combine the two lines of work.

A Real Merge
From the video: A Real Merge
  • Often, main moves on too
  • Both branches have new commits
  • Git combines them

Two lines of work

Here, the contact branch has a new commit. But main moved too. Someone made the headings red. Main can't just slide forward anymore. So Git creates a brand new commit, a merge commit, with two parents. It joins the two lines together.

Merging for real

Let's see it. We're on main. Git merge contact, with dash dash no edit, to accept the default message. Git says merge made by the ort strategy. Ort is just the name of Git's merging engine. The log now starts with a commit called merge branch contact.

git
git merge --no-edit contact
Merge made by the 'ort' strategy.
 contact.html | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 contact.html
git log --oneline -n 4
9139ee2 (HEAD -> main) Merge branch 'contact'
4f9f012 Make headings red
2ad55a2 (contact) Add contact page
f63a17a Link to about page

Summary

When both branches moved, git merge creates a merge commit with two parents. Next, a picture of the history, right in the terminal.

Key takeaways
  • Both branches moved
  • Merge commit, two parents
  • git merge --no-edit
Next up: Seeing the Graph — git log --graph