DEV Community

Cover image for Branches and merges
Luke Nguyen
Luke Nguyen

Posted on

Branches and merges

Introduction

This week on my journey through open-source, I continued to dive deeper into Git by practising creating branches and merging them back to main.

New features

In my static site generator, MINI, I decided to implement 2 new features and created different branches for each of them:

Implementation

Coding the new features were quite simple. For the lang flag, I just added an additional option object with the following properties:

l: {
    alias: "language",
    desc: "Language used when generating HTML",
    type: "string",
},
Enter fullscreen mode Exit fullscreen mode

The value of the newly added option would then be passed to each of the processInput and generateHTMLFile function to specify the language of the generated HTML file(s).

As for supporting Markdown's inline code ` syntax, I used regex to check for any instance of text enclosed with back-ticks and rendered them into HTML <code> blocks:

.replace(/`(.*?)`/gim, "<code>$1</code>") // replaces single backtick-enclosed text -> <code>content</code>
Enter fullscreen mode Exit fullscreen mode

Resolving issues

While I had no trouble merging issue #11 as it was simply a fast-forward merge, I ran into some problems when it comes to issue #10.

As it turns out, I mistakenly updated the content of mini-ssg.js in both my main and issue-10 branch, resulting in a conflict when I tried to perform the merge. I had to backtrack to find out where I made the changes and modified one of them to match the other.

Final thoughts

Through this experience, I had got a better grasp of how branches and commits connect to one another and the importance of checking for conflicts before merging. I also discover that while using git diff in the command line allows you to quickly review changes, in the case when the programmer modifies a large amount of content, using a text editor like VSCode will make the process much simpler as you can see the differences side by side.

Cover image by Yancy Min on Unsplash

Top comments (0)