Lesson 18 +15 XP

Git Merge

Git Merge

When your feature branch is finished, you usually merge it back into main.

The merge command

First switch to the branch you want to merge INTO, then merge:

git switch main
git merge feature-login

This joins the history of feature-login into main.

Fast forward merges

If main has not moved since you branched, Git can simply move the main pointer forward. This is called a fast forward merge, and it leaves a straight, simple history.

Merge commits

If main has new commits too, Git creates a special merge commit that combines both histories.

Check the result

git log --oneline

The log now shows commits from both branches joined together.

After the merge

You can safely delete the old feature branch:

git branch -d feature-login

The -d flag only deletes branches that were fully merged, protecting you from losing work.

TL;DR

  • Merge a branch into the one you are currently on.
  • Fast forward merges keep history straight.
  • New commits on both sides create a merge commit.
  • git branch -d deletes merged branches safely.