Merging

Merging brings the commits from one branch into another. It's how the work you did on a feature branch actually makes its way back into main.

git merge

Switch to the branch you want to merge into (usually main), then merge the other branch into it:

$ terminal
git switch main
git merge contact-form

Git figures out what changed on contact-form since it split off from main, and applies those same changes to main. What happens next depends on what's happened on each branch since they diverged.

Fast-forward merges

If main hasn't changed at all since contact-form was created, Git doesn't need to do anything clever — it just moves the main pointer forward to match contact-form's latest commit. This is called a fast-forward merge:

Terminal output
Updating 4a1f9c2..7c3e8a1
Fast-forward
 contact.html | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Merge commits

If main has moved on (someone else committed to it, or you did on a different branch), Git can't just fast-forward — it creates a new "merge commit" that has two parents, tying the two histories together:

Terminal output
Merge made by the 'ort' strategy.
 contact.html | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

This is completely normal and expected on any project with more than one branch of activity — you'll see plenty of merge commits in real project histories.

Merge conflicts

Sometimes the two branches changed the same lines of the same file in different ways. Git can't guess which version you want, so it stops and asks you to decide. It marks the conflicting section directly in the file:

</> index.html
<<<<<<< HEAD
<h1>Welcome to my site</h1>
=======
<h1>Welcome, friend!</h1>
>>>>>>> contact-form

The top section (between <<<<<<< HEAD and =======) is what's currently on your branch; the bottom section (between ======= and >>>>>>>) is what's coming in from the other branch. To resolve it, edit the file by hand into what it should actually say, remove all three marker lines, then stage and commit as usual:

$ terminal
git add index.html
git commit -m "Merge contact-form into main"
Note: a merge conflict isn't an error you did something wrong — it's Git being careful instead of silently guessing which change should win. Take your time reading both sides before deciding what the merged version should say.