Get Your Git in Order
By: Seoyoung Chloe Kim
Tags: Github, Git, Software Engineering, Software Development, Coding

Git is essential part of any developer’s life(unless you are using a different Version Control System). It makes our life and work(especially when you are working with others) so much simpler and efficient but to new developers it could be extremely difficult and troublesome. I have learned few lessons on Git best practices the hard way and here are some of the lessons I have learned.

1. Please, PLEASE hide your API

This one is a no brainer, yet if you have couple of sleepless nights coding or get caught up in fixing a bug for several hours, you might just forget it too. That’s what happened to me. At that point, I had already heard of many horrors stories about people who have failed to hide their API key and got charged tens of thousands of dollars in matter of hours, so I knew that I should take care not to publish my API keys, but it still happened. I just totally and completely forgot about it. Luckily for me though, Google(it was a Google Cloud Vision API key) caught it right away, as well as GitGuardian(which I was not subscribing at the time), a third party GitHub application that safeguards API keys, and informed me of the fact that my API key is out in the public. Again, thankfully, I was still at my computer when they sent me the notification and was able to discard the exposed API key and hide my new API key right away so there was no damage done to me. However, you shouldn’t rely on luck when it comes to API keys. Even if you avoid getting billed for thousands of dollars for exposed API key, it could makes your project look a little sloppy. Always get in habit of NEVER writing your API keys or tokens in your code in any place other than ENV file. There are already thousands of extremely well-written guides on how to hide any important information in your code, so I’m not going to write it too. Refer to this article on how to hide your API key: https://medium.com/better-programming/how-to-hide-your-api-keys-c2b952bc07e6

2. Branch out

Branching can be one your greatest allies when working on Git. We you are part of a team, it lets you work on something at the same time as your colleague without conflicts and makes it easy to keep track of what everyone is working on. It promotes collaboration between members of your team because when you know who is working on what in where and when each member’s work is neatly organized in to branches, it’s easier to have discussions to improve code that people are writing. Even when you are working alone on a project, making and committing to branch instead of master is important because even if you mess up something in efforts to fix a minor bug, you still have a place to go back to. Also, keeping separate branches for different features and bug fixes helps you move from one agenda to the other more easily. If everything happens in master, it is very easy for you to loose track of what you were doing before you got pulled to fixing a bug. So no matter how you are working(as a team or alone), get in a habit of making branches when you start working one something new and closing/deleting that branch once that part of work is finished and everything is merged to keep your repository clean.

3. Commit to your commit messages

As project gets bigger and bigger, what you(or your teammate) worked on yesterday can be quickly forgotten. When something starts to not work and you have no record of what you did the past day other than hundreds of lines of code you have written, finding out where things went wrong can get pretty stressful. That’s why you need to commit often and write descriptive commit messages each time. Your code needs neat yet descriptive comments and so does your commits. It will not only save you some time when you have to back track what you did to fix bugs but it will also help your teammates to know what you did and maybe even how you did it so that they can be aware of the impact it could have on the part that they are working on.