TIL Merging in Git
Tags: beginners, git, github, python
Published: 2023-09-28 17:57:08

Today I learned about merging in Git. I practiced with the feature by making a few branches that were created to hold four new features that I wanted to introduce to my [txt-to-HTML-converter](https://github.com/Pasqua101/txt-to-HTML-converter) (the new name is still a work in progress). I made four branches to try this out and filed issues for each of these branches. I'll discuss about them below.

### Implementing a Feature to Customize the lang Attribute in HTML
The [first issue](https://github.com/Pasqua101/txt-to-HTML-converter/issues/10) I created was an enhancement to the program. As the issue states, I wanted to allow the user to customize the `lang` attribute of the `html` tag by using an optional `-l` or `--lang` argument followed by `fr` or `en-CA`. If the user doesn't use the argument the argument will have the value of `en-CA` by default. Implementing this feature was really simple, all I had to do was add in and modify a few lines of code to support the feature. Once I was done, I tested it out a few times and everything seemed to work. I made updates to the readme to reflect this feature. I would have done a merge, but held off on merging it as I wanted to try merging my first three branches I made at once. Then merge my fourth one last since it would be created after I merged the first three.

### Adding Support for Markdown Code Blocks
The [second issue](https://github.com/Pasqua101/txt-to-HTML-converter) I made was to support Markdown code block. Just like the previous issue, this was an enhancement to the program and was very simple to do as well. I just had to write two lines of code in and modify a line in a function that handles parsing md files. The new lines I wrote were to convert any Markdown code blocks found in the converted HTML string to the `<code>` tag in HTML. The modification I made was to change what the function returns. The function originally converted markdown links found in the processed HTML string to the html `<a>` tag and then return the result. Instead of returning this result, I got it to hold the result in the HTML string being passed and then make it check for the code blocks and save the result to html string and then return. The function that I made the changes to was created by a peer of mine for a previous lab we had to do for our class. I made updates to the readme to reflect this feature, and I also waited on merging this.

### Adding Support for Markdown Horizontal Rule 
The [third issue](https://github.com/Pasqua101/txt-to-HTML-converter/issues/14) that I made was also another enhancement. I wanted the program to support horizontal rule (`---`) from Markdown and convert it to HTML. This was also another simple change. I went into the same function from the previous issue and added in one line. This line would look for `---` in the processed HTML string that was passed to the function and convert it to the `<hr>` tag in HTML. After I made this change I tested it out and saw that it was working. I updated the readme to reflect this change and waited to merge.

### Adding Support for Bold Markdown
Finally, the [fourth issue](https://github.com/Pasqua101/txt-to-HTML-converter/issues/16) I made was another feature enhancement. I wanted the program to be able to detect bold Markdown (`**text**`) and convert to the `<strong>` tag in HTML. Just like the other enhancements, this one was simple. I just had to add in one line of code the same function that was processing the HTML string which would give it the ability to detect the bold Markdown and convert it to its respective HTML tag. After that, I tested it out and saw that it was working. I then updated the readme to reflect the change.

### Merging All Three Branches
Once I had all the enhancements created I began to merge the branches with the main branch. I started off with merging my [first branch](https://github.com/Pasqua101/txt-to-HTML-converter/pull/11). The process was really quick and produced no issue from git. 

The [second branch](https://github.com/Pasqua101/txt-to-HTML-converter/pull/13) on the other hand, did produce an issue. Since both readmes were different I had to look at what was in the main branch and the branch I was merging. I opened the readme in Visual Studio Code (VS Code), which allowed me to see the differences. Thankfully, since the readme in the branch I wanted to merge just mentioned the feature I could get VS Code to accept both changes. So this way the readme in the main branch wouldn't get overridden by the readme from the branch I wanted to merge. I was also told to check my file_processor.py file, since I added the ability to support code blocks. All I had to do was accept the incoming changes from the branch I wanted to merge. I also had to do this with the txt_to_html.py file as well. Since the version of the file I had in the branch I wanted to merge did not have the optional lang argument. So I told VS Code to keep the version in the main branch.

For my [third branch](https://github.com/Pasqua101/txt-to-HTML-converter/pull/15) that I wanted to merge, I had to do the same thing. Update the readme to accept both changes. As well as accept both changes that were done in the file_processor.py and file. I also had to tell it to use the version of txt_to_html.py from the main branch. Since the branch made for my third issue did not have the optional lang argument. 

### Merging the fourth branch
After I merged the three branches, I then merged my [fourth branch](https://github.com/Pasqua101/txt-to-HTML-converter/pull/17). Just like the first branch I merged, this one was quick. Since the branch I was merging was on what is essentially an updated version of the main branch, because there were a few extra lines. So I didn't have to specify which branch I wanted to merge or look at the differences and move certain things around.

### Conclusion
After I merged everything, I learned both how useful and powerful branches can be to a developer. I really liked how I can have an isolated environment to test out new features I want to implement without having it affect my main branch. Plus, if I decided to head in a different direction or give up on the idea, I can return to the main branch and continue working there or make a new branch to try out something else. It also gave me a better idea at how pull requests work, since I had to make pull requests for every merge. Thanks again for reading and see you in my next post.