This week was truly eye-opening as I dove into the concepts of branching and merging in Git. At first, the workflow felt a bit tricky to grasp, but after carefully going through the readings from the Git book:
3.2: Basic Branching and Merging, 3.3: Branch Management, 3.4: Branching Workflows
I started to understand the power behind these features. Once I practiced them in Lab-03, it honestly felt like working with a Git-powered time machine where I am managing multiple timelines of a project and then bringing them back together.
Parallel Feature Development
For the lab, we had to build two features in parallel branches and later merge them into the main branch using different merging strategies. Here’s what I worked on:
1. Last Modified Timestamps
The goal was to display file modification timestamps in each file header of the output.
Example:
### File: src/main.js (Modified: 2024-01-15 14:30:22)
const helper = require('./utils/helper');
To implement this, I used Python’s subprocess library to run git log
commands for individual files and extract the last modified information.
I first created the issue on GitHub (Issue #9), and then worked on it in a dedicated branch.
2. Statistics Enhancement
This feature expanded the summary section of the tool by adding more detailed statistics such as:
- Total files and total lines
- Breakdown of file types
- Largest file details
- Average file size
Example output:
## Summary
- Total files: 15
- Total lines: 342
- File types: .js (8), .md (3), .json (2), .css (2)
- Largest file: src/main.js (89 lines)
- Average file size: 22 lines
I have done this by going over files and keep track of the type counts, finding the largest file by line count, and then returning the structured result back to the caller. The helper functions included logic to group file types, identify the largest file, and compute averages.
Before start working on the feature implementation, I had created an Issue #10 to describe the functionality expected.
Merging the Timelines
Once both features were implemented, it was time to bring them back to the main branch.
I tried merging the branch for Issue #9 first. As It was branched off of the main branch the merge was fast-forward and was done in a single commit.
But when it came to merge the second Issue #10, I faced a merge conflict. It was due to a README.md file, where the Issue #10 branch had changed the same line of code which Issue #9 had changed. It confused git and caused the merge conflict. To fix this I used the vs code editor's conflict resolver feature, which provides very clean UI of current and the upcoming features. So it created a commit when I resolved the conflict.
Overall, This lab taught me how powerful Git branching and merging really are. At first, it was overwhelming to handle multiple branches and merge strategies, but once I practiced, it felt natural and even fun.
Top comments (0)