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 master.

Run

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

Result

$ git switch style
Switched to branch 'style'
$ git merge master
Merge made by the 'recursive' strategy.
 README | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 README
$ git log --all --graph
*   a33535d 2023-11-27 | Merge branch 'master' into style (HEAD -> style) [Alexander Shvets]
|\  
| * 8542252 2023-11-27 | Added README (master) [Alexander Shvets]
* | 837d65e 2023-11-27 | Renamed hello.html; moved style.css [Alexander Shvets]
* | 069147d 2023-11-27 | Included stylesheet into hello.html [Alexander Shvets]
* | 058b5ca 2023-11-27 | Added css stylesheet [Alexander Shvets]
|/  
* 75abe6d 2023-11-27 | Added copyright statement with email [Alexander Shvets]
* 43c6fc8 2023-11-27 | Added HTML header (tag: v1) [Alexander Shvets]
* 91051af 2023-11-27 | Added standard HTML page tags (tag: v1-beta) [Alexander Shvets]
* e26eae7 2023-11-27 | Added h1 tag [Alexander Shvets]
* b01c348 2023-11-27 | Initial commit [Alexander Shvets]

Through periodic master branch merging with the style branch you can pick up any changes or modifications to the master 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 master branch conflict with changes in style?