Don’t Lose Your Code; Version Control

April 24, 2019 BY Perry Auld

20190415 - version control

If you deal with code for your business, or even if you’re not going anywhere near it, I hope you’re using some kind of version control. Version control is a very common practice for software development, and yet I’ve seen many places that don’t use it. If you’re not, it’s time to start -- right now. As some old proverb goes, “the best time to plant a tree was 20 years ago. The second-best time is now.”

What is “Version Control”?

First when we’re talking ‘version control,’ also known as ‘source control’ or ‘revision control,’ we’re talking about a system of saving changes made to documents. For this post, we’re going to look at the reasons and benefits for using a version control system, such as Git or Mercurial. These systems save the history of your code in what’s called a repository. Each of these and more are open source, so they won’t cost you any money. They will, however, save you a lot of money.

The Backup of Your Work

No matter your business, there will undoubtedly be some application or piece of software that is yours, not bought or licensed; and I’m sure that piece of software is essential to running your business. The code for your business is the life-blood of your business. What if you lost the data on your computer? What if the server with your internal system was damaged? The repo is your backup copy. With it, you know you always have a safety net in the event of the unexpected.

The Historian of Your Work

Maybe the save button can keep that backup of your work just fine. The repository does one better: it not only saves your work; it saves the entire history of your work. Every minor change in any small part of your code is saved in a timeline of work, through what’s called a ‘commit.’ This gives you the ability to go to any point in time that you’ve saved something and see what the code looked like at that time. It’s like layering every change on top of each other, to arrive at where your code is in the present. As changes are made, and new features are added, things may not work as expected. Defects will undoubtedly start getting into the code, causing unexpected errors. This is the biggest benefit of a repository; you can always go back to a point in time when things worked perfectly.

The Experiment of your Work

Because you can always go back to when things were working and stable, why not loosen up and experiment some? The next biggest benefit to using a repo for you code is you’re not limited to one timeline of work; you can have as many timelines as you want. Through a feature commonly known as branching, it’s possible to create new ones at any point in time. From there you can build a new feature, try to upgrade an existing one or try to fix that one thing that’s never quite worked – all while leaving the core of stable code alone and undisturbed. When you’re finished and that new feature works, you can merge it into the nice stable code. Now your new feature is part of the core as well.

The Collaborator of your Work

So now you’ve got a safe backup, a history of your work, and the means to make isolated changes. I’m sure you’re not the only one doing all this work. With version control repo, you’ve also got the means to allow multiple people to all work on the same codebase, at the same time, without bumping into each other. With branching and merging, multiple people can work on different things and each bring them back to the main code without losing work. When two branches are merged together, you can see the changes from each. What if two people changed the same line of code? These conflicts will be highlighted. You typically have to resolve them yourself, but that’s better than introducing new defects into the code. Given different branches, you don’t have to worry about someone else’s work being erased when another adds to it.

Get to It

Practicing version control is simple and should be essential for every business. You get a safe backup of all the code your business uses. Not only a backup, but the full history of your code, so if something breaks, you can always go back in time to when it worked. Through branching & merging, you don’t have to worry about breaking things in the first place. It lets you bring in more people to work on the same code, speeding things up in a safe and scalable way. Make sure your business has a code repository and procedure setup today.