Step 5 / 6 ยท Merge

Merge: bring the changes together

Merge brings two histories together in a new commit.

Illustration: two stone paths meet and become one in the garden
In the garden

The fence is fixed and the flowers look beautiful. Now the two paths meet: one garden with everything in it.

In practice

On main, git merge flowers brings in the history of the flowers branch. Git creates commit M, which has two parents: the latest commit on main and the latest one on flowers.

If both changes touched the same part, a conflict appears. Do not panic: open the file, choose what it should look like, then run git add and git commit. Finally, test the garden as a whole.

Commands

git switch main  # go back to main
git merge flowers  # bring in the flowers (commit M)
# in case of conflict: edit, then
git add . && git commit  # finish the merge

Tip: A completed merge is not a tested merge. Run the project before sharing it.

What the history looks like

AfirstBpathCfenceDflowers 1Eflowers 2Mmergemain