DEV Community

Hitesh Sachdeva
Hitesh Sachdeva

Posted on

Working in Parallel Branches: Lessons from My Project

In the recent week, while working on my project Share-My-Repo, I learned how to work with multiple branches at the same time. This was my first time doing it, and using parallel branches helped me develop features and fix bugs without affecting the main code, which is very important in real projects.

Branches and Tasks

I created separate branches for different tasks:

  • issue-6 – Added the --line-numbers option to show line numbers in file outputs.
  • issue-7 – Added the --preview option to display only the first N lines of each file for easier reading.

What I Did

In my project, I worked with two separate branches, issue-6 and issue-7, both starting from the same commit on main.

  • In issue-6, I implemented the --line-numbers feature so that whenever a user uses this flag, the output shows line numbers for all code files.
  • In issue-7, I implemented the --preview<N> feature, allowing users to see only the first N lines of any file for easier previewing.

After successfully completing both features, I first merged issue-6 into main. This merge was straightforward and used a fast-forward merge since there were no changes in main yet. Next, I tried merging issue-7 into main. This time, conflicts arose because main had changed after merging issue-6, and some edits in issue-7 overlapped with the same lines in certain files. so i merged them using three-way recursive merge.

Problems I Faced

The fast-forward merge of issue-6 into main was straightforward and completed without any issues.

However, when I tried to merge issue-7 into main, I faced several conflicts. conflict-merge. Some of the problems included:

  • Overlapping edits: Both main (after merging issue-6) and issue-7 modified the same lines in some files.
  • Combining changes: In some cases, I needed changes from both branches. For example, one branch updated a function with its own arguments, and the other branch updated the same function with different arguments. I had to manually merge the function so that it included both sets of arguments.
  • Challenges After Merge: After merge, the code was not working, so I had to test it thoroughly and make it work; the issue was due to the position of function arguments.

Lesson Learned

I learned that working with parallel branches requires careful planning, especially when multiple features modify the same parts of the code. I also learned the importance of testing thoroughly after merging to make sure all features work correctly. Manual conflict resolution is often necessary when automated tools cannot handle overlapping changes, and I will follow these practices in my future project

Top comments (0)