AI Hints
Home›Git & GitHub Tutorial›Working with Branches
Git & GitHub · Lesson 44 of 144

Merging

Git merge.

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

When your feature is ready, you bring its commits into main. That's called merging. You switch to the branch you want to update, and merge the other branch into it.

Merging
From the video: Merging
  • The feature is ready
  • Bring it into main
  • git merge

Merge the feature

First we switch to main, because that's the branch we want to update. Then git merge contact. Git says fast forward, and lists the files that changed. Now the log on main includes the contact commits. The feature is in.

git
git switch main
Switched to branch 'main'
git merge contact
Updating f63a17a..90dc6d2
Fast-forward
 contact.html | 1 +
 index.html   | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 contact.html
git log --oneline -n 3
90dc6d2 (HEAD -> main, contact) Link to contact page
2ad55a2 Add contact page
f63a17a Link to about page

A fast forward

Here's what happened. Main hadn't moved since the contact branch started. So Git didn't need to combine anything. It simply slid the main label forward, to the latest contact commit. That's called a fast forward merge.

Clean up

The contact branch is finished, so we delete it. Git branch dash d contact. It's merged, so Git deletes it happily. Its commits live on, in main.

git
git branch -d contact
Deleted branch contact (was 2ad55a2).

Summary

Switch to the branch you want to update, then git merge the other one. If main hasn't moved, it's a simple fast forward. Next, merging when both branches have moved.

Key takeaways
  • git switch main
  • git merge <branch>
  • Fast-forward: main slides along
Next up: A Real Merge — when both branches moved