DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 966,155 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
cychu42
cychu42

Posted on

Merging Branches

Today, I'm just going to talk about what it's like to merge branches using Git.
Git is a wonderful tool that helps you manage your repo. You can switch back and forth between different snapshots of your code you made for each thing you want to add/change and work on them separately. Once you are good, you can combine/merge them back to your main snapshot. A snapshot is called a commit, and it and the history of commits leading up to it is a branch.

The Workflow

To address two changes I wanted to add to the static site generator I talked about in previous posts, I first opened one issue for each: 1 2
Then, I made a branch to work on for each them: 1 2
Spoiler: I did merge them back to the main branch, as you can see!

Once I'm satisfied with the work, I merge them back to the main branch. If there's any conflict, git would put some conflict markers for me to address before continuing. Basically, if it doesn't know which version of the code to keep, it will do that for me to decide. Luckily, it's pretty smart. However, I did some testing just in case. I mean, that's the safe thing to do. And no, everything turned out to be fine thanks to how smart it is.

What are these changes?

Just read the links...I'm kidding.
The first change was adding support to allow language selection for the HTML output files.
I added the option -l or --lang to allow users to specify what language they want to use.
This will decide the lang attribute in the HTML output file. For example, -l pt-BR will indicate the file is in Brazilian Portuguese, and it will have <html lang="pt-BR"> in the HTML code.
The default would be Canadian English: <html lang="en-CA">

Changes

  • Added code to allow and recognize -l / --lang option.
  • Added a variable to hold the language value, with en-CA as default.

The second change was adding support for horizontal rule in Markdown input files. Essentially, this allows the tool to parse --- in Markdown files and convert them to <hr> tags in the HTML output files.

Changes

  • Added code for file writing to replace --- or longer variations with <hr> tags in the HTML output files.
  • Added code to ignore lines made of tags, such as <hr>. (Only <hr> for now.)

For both, I updated the README.md and help option to let users know these are part of the tool.

Problem And Learning

I forgot to include some of the text explanation for the changes I made in README.md and the help option, when I merge the branches. I ended up adding them afterwards. I should probably remember to include them in the future for organization sake. Other than that, it's mostly stopping myself from wanting to edit a lot of things at once and sticking to the focus of each branch. Sometime, I just see some code or slight formatting issues that I want to edit right there. Hey, I managed, and this teaches me to note things down to address separately.

Top comments (0)

You’ve already scrolled down this far, why not join our community of 900k+ developers all learning together?