Pending ...

Automating and securing code management with Git

I’ve joined Human Managed — a data company that empowers decision — in late December 2021 as a front end developer. In a short amount of time, I went through a steep learning curve, working with technologies and processes that I have never worked with before.

One of those is Git, a distributed, open-source version control (VCS) that enables you to:

  • store code
  • track revision history
  • merge code changes
  • revert to earlier code version when needed

Back in my college days, I used to code without any version control tool like Git. What I did was copy and paste source code folders and rename it with a version number. My reasoning back then is, since I do code alone, then there’s no point in using a version control system. Lo and behold, this idea backfired to me in my thesis project. There was a time when I needed to update a block of code for a fix, and it took me hours to do so.

git1.webp
I used to agree with the guy at the bottom😂

I knew that I needed to learn git when I joined HM. I won’t be coding alone anymore since I’ll be collaborating with my colleagues. When I was trying to learn it during my first few weeks, I initially thought it was really complicated since there are a lot of commands that you need to understand. But when I started to contribute in our internal codebase, I (also with the help of my colleagues) managed to learn it along the way. I have lots of realizations on how this tool can benefit myself before and could’ve made me more productive back then, how I wish I learned about it sooner!

How Human Managed uses Git

On a day-to-day basis, we use git and GitLab to store our source code, keep track of our changes for every apps per microservices and run a CI/CD pipeline to ensure that stages are automated and done correctly.

Through git, we have a commit ID which keeps track of our changes. We can always go back to whichever version we have, in any cases that we wish to.

For example, imagine you are working on a feature within a webapp and made around six commits already. You tested the application, then found that there is a bug in your app. Upon checking, you realized that the bug was caused by the initial commit you had in the source code. With git, you can revert a change and undo it, so you can go back to the original state of the source code.

git2.gif

In our applications, we use GitLab as our git-based web platform environment for version control and source code management. Every day, there are changes to be made in the codebase. A developer can work concurrently with the other one through git since we utilize its branching functionality and it being a decentralized version control system. We create a branch for a specific update in our webapp, and merge it to the main ‘production’ source code once it’s finished. This way, we are not dependent on each other if we want to make changes to our applications. We can do things seamlessly without the worry of having any conflicts with what we are doing.

CI/CD Automation with GitLab

gitlab.webp

GitLab is used as our DevOps platform. Since it is git-based, we use GitLab as our remote repository to store our source code. An event is triggered via git push/commit to the remote which will execute a CI/CD pipeline through GitLab. We use it to run automated build, test, and deployment. Through gitlab, we can deploy apps immediately without the need to wait for someone to finish something, since steps are already automated.

Every action we do within our internal repositories are tracked via webhook which is configured in a CI channel wherein relevant individuals are added. We use this as our collaboration method to notify and make everyone aware on what’s happening to our apps in microservices.

git example.webp
webhook notification in slack

Using GitLab enables us to automate majority of version control and source code management. It’s beneficial for software engineering since manual steps are already taken out of the picture through its automated devops functionalities.

devops.webp

Imagine doing manual build, test, and deployment for your applications. You’ll go back to the days where it’s not as efficient as compared to the automated stages that a devops tool like GitLab can offer. For sure it must have brought a lot of headaches to every developer before! Lucky enough, we live in an advanced tech-era now where everything can be automated already.

doesnt look good.gif
don’t be like this guy

The screenshot below is an example of .gitlab-ci.yml file. In layman’s term, this is the set of instructions that you need to configure to automate all the actions/stages that you’ll be automating in your application.

cifile.webp

Someone just needs to understand how to write this CI file, and all the end-to-end stages for CI/CD will be automated already. That’s how handy and powerful this file is!

This is just the beginning of our code automation story. Just like git, this narrative can be further branched out to areas like application security, automated deployments, and gitops. But that would be for another blog! 😊

Note: This blog was originally published in August 2022 and has been updated for accuracy.