As computers become more powerful and the internet becomes increasingly ingrained into our daily lives, the role of the web developer becomes more and more complex.
Just like there are a whole lot of tips out there for those learning, so too a wide variety of coding tools exist to help programmers do their jobs more effectively, the Version Control System (VCS) arguably being the most important.
But what is version control, and how do developers and software engineers use it? Let’s find out!
1. What is version control?
A VCS manages and tracks changes to documents, files and other collections of information.
Popular version control systems for developers include SVN, Mercurial, and the immensely popular Git (not to be confused with GitHub). These tools help us prevent issues we’ll certainly all come across at some point in our web development careers. These issues includes:
- Losing code changes—no more accidental deletions!
- Conflicting code changes
- Difficulty in tracking project progress
- Redeployment challenges—are you deploying the correct version?
It’s important to look closer at these potential issues, which is what I’ll do next.
2. Six reasons why version control systems are useful
So now that you know what is version control, it helps to see how it fits into your daily work. To give you a better idea as to why these systems are useful to coders, I’m going to run through several different scenarios where you’ll be thankful you’re working with a version control system.
I’ve made a change I didn’t mean to make
Whether it’s a change to a single file or countless changes to your code base, we’ve all been there; the realization that you have just altered or deleted something you shouldn’t have.
As the name suggests, the core concept of a Version Control System is the creation of versions of your code over time. Implicit in this functionality is the ability to revert to an old version of your code and undo changes that have been made.
I’ve made some changes, but I don’t remember what they were
When working in a large file or a large code base, it is easy to get lost in your own work.
With your code being managed by a Version Control System, you can easily see the changes you have made since the last time you have committed your code (“committing” your code is when you save the changes to code you have been working on). When using Git, the git diff
command can be run in your project, to show the files that have been added, altered or deleted or it can be run on different versions of a particular file to see the differences.
This feature is so useful that plugins have been created to integrate this behavior directly into most code editors.
My computer crashed and now I don’t have access to my code
Most VCS can run on a server, so your changes can be tracked and backed up remotely.
This is very useful as it creates a copy of your work that does not depend on which computer you use. It only takes a few easy terminal commands: You can git remote add
a server to which you can backup and git push
your code to it.
In the event of a computer crash, you can simply git fetch
your codebase from that server and get to work.
We can’t all work on the same file, can we?
When you are working with other developers, collaborating on tasks can be difficult.
If multiple developers work on the same file at the same time, it becomes very easy to accidentally overwrite someone else’s changes.
Shouting “I’m working on XYZ right now!” to your fellow coder is not the best way to work. Instead, you can set up a remote Version Control System, where developers can git fetch
a copy of the code onto their machine and work independently from other developers.
Once everyone is done with their work, it is easy to merge all the different versions into a common file that incorporates everyone’s modifications.
Sore throats at the end of a long day are now a thing of the past (especially if you’re working as a remote web developer).
I’m not sure what I accomplished today
Version control systems allow you to have a good overview of what you’ve accomplished for a given period of time.
If you are committing your code regularly (ie, saving changes to your code), every time you fix a bug for example, you can easily see a log of all your commits (a commit is a marker that contains all of the changes that you’ve made) and have a nice list of all the tasks you have completed.
This history also allows you to track down changes to specific lines of code, so you can source why a change was made, or how a bug first appeared.
Developers have also created time-tracking tools that extend Git’s functionality to allow for time measurement as well as version management.
This displays the amount of time between commits, creating a realistic view of how long it took you to solve an issue. This can be particularly useful when you are freelancing and you have to create invoices for your clients, or calculate how long it will take you to finish a project.
I want to try something, but I’m scared I’ll break something else
Version control systems allow for more advanced workflows which make working on a large codebase easier.
A powerful concept known as “branching” is widely used in the software development industry. Branching is a great way to isolate changes to your code and allows for easy reversing of problematic code.
So, what is branching? Like the name suggests, branching allows you to create a “master branch” (in grey below), which usually coincides with the code that is in production. Different versions of the code, named branches (in yellow below), shoot off this master branch for every change in functionality you want to implement.
This concept is incredibly powerful as it allows you to experiment with your code, without changing the “master branch”. The master branch continues to evolve independently of whichever branch you are working on.
When you are done with your changes, you can merge your branch back into the “master branch”, which will apply both the changes in your branch and the changes that have occurred on the “master branch” in the meantime.
Branches are usually created for any change in functionality, for example the creation of a new feature or fixing a bug.
The isolation of changes that branches provide allows you to experiment with your code without the fear of breaking things in your live code, because, should things not work out, you can simply erase the branch and nothing in the “master branch” will have been affected by it.
Final thoughts
Whether you are working on a complex code base or simple scripts, it’s always a good idea to invest some time in learning just what is a version control system, and how to use it habitually.
Version control systems are incredibly powerful tools that can help you get things done more effectively, make it easy to reverse what you’ve done, aid experimentation and back up your work—altogether making your life as a web developer significantly easier.
To start working with version control you’ll need to start coding, and there’s no better way to dip your toes in the field than CareerFoundry’s free 5-day coding short course. In it, you’ll build and style your first website using HTML, CSS, and JavaScript!
If you’d like to read more about the world of coding, check out these articles: