“Git merge …” succeeded, wait which branch I am on again? OMG, not master… “Git reset…”
Yes, You read it right. This was my struggling and I did it wrongly four times to finally do it correctly. This week in the topic of Open Source Development, we gotta learn about the different strategies to combine different branches into the master branch. The center of the process is git command
git merge. The idea is quite straightforward: you checkout a new branch, do some work on it, checkout back to the master branch then run
git merge for two branches to merge together. Everything was smooth until I forgot which branch I am on.
In lab 3, we were asked to add two new features among a few provided by the instruction. You would need to implement each new feature in a completely separate branch and then merge both of them into your original/master branch before pushing it to github. My first mistake was not to checkout a new branch before working on a new feature. This is because of my habit that I only work on the master branch, so I jumped right into the coding without thinking that I had to checkout a new branch first. It took me sometimes to reverse the changes and first lesson learned. Lesson number 1: “Always checkout a new branch before implement a fix or a new feature”.
All seemed to be smooth from that point on. I went on to complete the two new features on two different branches called “issue-8” and “issue-9”. I was so confident that I got this under control. I merged the branch using
git merge and suddenly realized that I had made another mistake. I forgot to checkout back to the master branch as I was on “issue-9” branch. The merge was unsuccessful. Lesson number 2: “Always checkout back to the original/master branch or where the branches started branching out before using
This lab allowed me to realize my current limit and bad habits that could cause problems in my future career. In software development, you need to be very accurate. One minor mistake could lead to loss of millions dollars for the company. This lab also provided me a chance to practice on merging branches which will be important in the future.
You can find details of my two issues and the commits that I used to fix them below: