23. Merging

Goals

  • Learn how to merge two distinct branches to restore changes to a single branch.

01 Merge the branches

Merging brings changes from two branches into one. Let us go back to the style branch and merge it with main.

Run

git switch style
git merge main
git log --all --graph

Result

$ git switch style
Switched to branch 'style'
$ git merge main
Merge made by the 'ort' strategy.
 README | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 README
$ git log --all --graph
*   a33deed 2023-11-28 | Merge branch 'main' into style (HEAD -> style) [Alexander Shvets]
|\  
| * ee16740 2023-11-28 | Added README (main) [Alexander Shvets]
* | 0ee0113 2023-11-28 | Renamed hello.html; moved style.css [Alexander Shvets]
* | 903eb1d 2023-11-28 | Included stylesheet into hello.html [Alexander Shvets]
* | 555372e 2023-11-28 | Added css stylesheet [Alexander Shvets]
|/  
* 9288a33 2023-11-28 | Added copyright statement with email [Alexander Shvets]
* b7614c1 2023-11-28 | Added HTML header (tag: v1) [Alexander Shvets]
* 46afaff 2023-11-28 | Added standard HTML page tags (tag: v1-beta) [Alexander Shvets]
* 78433de 2023-11-28 | Added h1 tag [Alexander Shvets]
* 5836970 2023-11-28 | Initial commit [Alexander Shvets]

Through periodic main branch merging with the style branch you can pick up any changes or modifications to the main to maintain compatibility with the style changes in the mainline.

However, it does produce ugly commit graphs. Later we will look at the option of rebasing rather than merging.

02 Next

But what if changes to the main branch conflict with changes in style?