Skip to the workspace
Pebellslearn by building
Branching Basics  ›  Capstone Project

Merging Basics

Merging Basics 12 mingit merge brings another branch into the current one, either by fast-forwarding the label or by creating a merge commit, and stops for you to resolve conflicting lines.

git github / Merging Basics

Explore each scene at your own pace.

01 · The rule

The rule

Merging Basics

The vegan pancakes were a success. Now that recipe needs to come home to main, where everyone reads it. Merging is how the work from one branch joins another, and knowing which kind of merge Git will do removes most of the mystery.

The rule

Stand on the branch that receives, then merge in the branch that gives.

Merging always brings another branch into the branch you are on:

git switch main
git merge vegan-pancakes

Git then does one of two things.

Fast-forward. If main has not moved since the branch was created, main is simply behind. Git slides the main label forward to the branch's tip. No new commit is made.

Updating 9b2d7e4..c41a0f2
Fast-forward
 pancakes.md | 6 +++---

Merge commit. If both branches gained new commits, their histories have split. Git combines the two tips, using the commit where they split as a reference, and records a new merge commit with two parents. Your editor may open with a ready-made message such as Merge branch 'vegan-pancakes'; save and close it to finish.

Conflicts. When both branches changed the same lines of the same file, Git cannot choose for you. It stops and marks the file:

<<<<<<< HEAD
2 cups milk
=======
2 cups oat milk
>>>>>>> vegan-pancakes

The part above ======= is your current branch; the part below is the incoming one. Edit the file to the version you want, delete the three marker lines, then git add pancakes.md and git commit to finish the merge. If you would rather back out, git merge --abort returns everything to how it was before the merge. Resolving tricky conflicts and choosing between merge strategies are topics for more advanced Git work.

After a successful merge, the branch has done its job: git branch -d vegan-pancakes.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.