Git, How we use it?! Am I wrong!!

Syed Sirajul Islam Anik
4 min readMay 2, 2020

--

It’s been more than 5 years now I have been using git. Back in 2014, I was working for a client of mine when I was working as a freelancer in oDesk (currently Upwork). That time, I didn’t learn anything about git. Possibly I didn’t even hear about that. I was versioning my projects like the following meme.

From: https://petapixel.com/assets/uploads/2015/07/psdrevisioning.jpg

After that, in 2015 another client told me, “I want to hire you. I liked your version control. But you will need to learn git.”. After that, I learned git. Git saved my ass once, sudden powercut deleted the whole file I wrote throughout the night. I had checked JetBrains and found a copy of that file.

Anyway, I don’t know if I am wrong the way I am using it. But I find it convenient.

How I used git?

At Pathao, we the developers of the same group used the same repository to push our feature branches. Merge the required branches in staging. When it was ready to be deployed to production, then we merged that feature branch in production and possibly delete the feature branch. That time, I thought it’s the correct way. Didn’t look for better opinions.

But, here at Telenor Health, Currently known as Digital Healthcare Solutions, the approach is different. We fork from the main repository. We work in our repositories and push the feature branches to the staging or master using PRs. Now, it seems good to me. People change, opinions do change as well. It’s obvious.

But the problem was somewhere else. One day I created a PR from with my new feature branch to the dev. There was a merge conflict. To resolve the merge conflict I used GitHub’s merge conflict resolver. I didn’t know the problem. When I then went to create a PR to master branch from my feature branch, I found that my feature branch contains all the dev branch’s code. Boom!! I was all done. ALAS!!!

I had to spend a whole day to fix that problem. Tried cherry-picking (not popping 🙄) but wasn’t reaching anywhere. I had to copy and paste the code the whole day. I might be wrong. Might have some other way round. But I learned a lesson that day. Now, I found a clean way to get the job done. Let’s check how I do it…

How I use git now?

Whenever I am assigned to work in a project either from scratch or any legacy one I ….

  • Firstly fork the repository. Then I clone the repository. I make sure that I always put the actual repository’s connection as my upstream repository.
  • I always keep my master | staging | dev branches updated with upstream’s master | staging | dev branches. They’re actually a mirror.
  • Then whenever I want to create a feature branch, I always create it from my master branch.
  • When I am done with the feature branch, I push it to my remote repository. It this way, the original repository stays clean.
  • Whenever I need to push the code to the staging or dev branch, as I said before, I keep my these branches mirror to the original repository’s branch, I simply merge my feature branch to that staging or dev branch. If the merge conflict occurs, I resolve them locally being in that branch and push to my remote repository.
  • When my staging and dev branches contain the feature, I create PRs and send them to corresponding branches.
  • When the testing is done and the feature is ready to be deployed in production, I make sure my master branch is updated with upstream/master. Then I merge my master branch to the feature branch. This way, my master branch is less affected. My feature branch is updated with the master. Then I merge my feature branch to master again. You may think that I do one step more. But it’s okay. My master branch is not affected yet. It’s up to you tho.
  • Finally, I send a PR from my master to upstream/master.

By doing this, I kept the original repository having no feature branch. I don’t mess up with my feature branch. And finally, everything is less messy.

If you think I’m doing something wrong, leave a comment. We may have a conversation and find out which one is good.

Edit: Found an URL for git related questions shared by Abu Ashraf Masnun bhai on a Facebook group.

URL: http://41j.com/blog/2015/02/common-git-screwupsquestions-solutions

Seems like, I used most of them. 😜

During this Covid-19 stay safe, stay healthy. Pray for all. And even afterward.

Happy coding. ❤

--

--

Syed Sirajul Islam Anik

software engineer with "Senior" tag | procrastinator | programmer | !polyglot | What else 🙄 — Open to Remote