We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Merge Commits

A merge commit is the result of merging two branches together.

Click to play video

Let's say we start with this:

A - B - C    main
   \
    D - E    feature_1

And we merge feature_1 into main by running this while on main:

git switch main
git merge feature_1

The merge will:

  1. Find the "merge base" commit, or "best common ancestor" of the two branches. In this case, A.
  2. Replay the changes from main, starting from the best common ancestor, into a new commit.
  3. Replay the changes from feature_1 onto main, starting from the best common ancestor.
  4. Records the result as a new commit, in our case, F.
  5. F is special because it has two parents, C and E.

After:

A - B - C - F    main
   \     /
     D - E        feature_1

Happy path: keep main checked out. If you want to make the branches diverge more first, add one commit on main and one on feature_1, then use Merge while still on main to create a two-parent merge commit.

Interactive example available with JavaScript enabled.

Assignment

Your current webflyx commit history should look like this:

A - B - C - E    main
         \
           D     add_classics

Run and submit the CLI tests while still on main.

Tips

Remember, if you mess up a commit message, you can change it with the --amend flag. For example:

git commit --amend -m "F: Merge branch 'add_classics'"

If you prefer a GUI editor over Vim, you can set one as your default:

# Zed
git config --global core.editor "zed --wait"

# VS Code
git config --global core.editor "code --wait"

To save and exit the editor:

  • Vim: Press I to enter Insert Mode, then type. To save, press Esc, type :wq, and hit Enter.
  • Nano: Type immediately. To save, press Ctrl+X, then Y, and Enter.
  • Zed / VS Code: Type, save (Ctrl+S), and close the window to finish.