Version control can save your ass

4 min read
Mendel Kurland

I nearly lost my trusty steed, Pancho. Luckily, I had checked a copy of his registration papers into GitHub, and the border patrol let us go after a three-hour interrogation and a bottle of rotgut mescal.

OK, maybe that's not *exactly* what happened. But I did have a time back in high school where something like GitHub or Bitbucket® would have been a lifesaver. I had just finished writing a term paper. My edits were complete, and I’d read and re-read the document for accuracy and spelling. I closed the file to make sure I had saved the changes, and noticed something else on my desktop I wanted to clean up, and then the unthinkable happened.

I accidentally deleted my term paper.

Unfortunately, I’m the type of person that shift-deletes files so they never reach the recycling bin. I sat at my desk with the worst gut-wrenching feeling, and it would be years later until I realized that I wasn’t alone. As I sat in front of my computer trying to decide how to recover from my monumental computer cleanup, I couldn’t help but think there should be a better way to manage files that doesn’t involve writing the entire paper over again. If only my teacher understood the peril I’d endured when she gave me feedback that my paper “lacked substance.”

Version control to the rescue

Version control was created for the purpose of saving developers from mishaps like mine. It also enables multiple developers to collaborate on the same piece of code at the same time. It’s a safeguard that keeps multiple developers from overwriting each other’s work, and helps to inform future developers about the previous change and development process.

In short, version control is a change management system.

Typical version control systems consist of two key components: the repository and the working copy.

The repository

A repository is created by importing files from a local directory on your computer to the version control system. Typically files are only imported once. This import creates the initial repository. For instance, a developer might decide to begin using version control with the code of a particular website. From the Web server, the developer would import files to a new repository. Once created, this repository (or "repo" for short) is the central point-of-truth within the system.

The working copy

Think of a working copy as the development copy of the files in the repo. A checkout function is used to create a working copy of files in a development environment that doesn't affect the repository. It is this copy of files that the developer works on, enabling her to safely add functionality and change the original code without worrying about corrupting the master. Each developer can have her own working copy.

Once new features or changes are made in the working copy, a new version of the code might be sent back to the repository for all collaborators to access. A commit is used to send changes back to the repository. If for some reason changes have been made by multiple developers to the same file at the same time, a conflict occurs. Consequently, the person committing changes will be forced to merge changes, or accept a particular set of changes before a commit can occur.

While this is a basic overview of version control systems for developers, the lingo is explained more in-depth on the revision control Wikipedia page.

Now, lets talk synonyms. Version control can be called a lot of things (just don’t hurt it’s feelings) including revision control, source control, code management, distributed version control as well as a host of things that can't be printed in a family newspaper. However, all these terms mean the same thing.

There are many different version control systems, some self-hosted and some hosted by a third-party. Some of the most popular version control systems are:

Self-Hosted Solutions

Hosted Solutions

For beginners, I recommend using Bitbucket. The system is free, simple to use, and Atlassian® (the company that created Bitbucket) does a knock-up job of explaining how to create and import files into a new repository.

I’ve only just scratched the surface of what version control can do, so if you’d like to add your thoughts, recommendations, or questions, leave them in the comments or tweet @ifyouwillit. And, if at this point you’re thinking, “I’ve got this,”cruise over to my article on creating a Git .ignore file, and give that a spin!

Products Used