When collaborating with co-workers on a development project, you may have experienced frustrations when someone overwrites your work, or when you have to constantly swap files, or even having to maintain duplicated versions of the same file.
You may have invented ways to combat this by emailing files between colleagues or date stamping each file but this method is extremely painful and non-productive.
This is why version control was invented. It helps manage, organise and share projects by preserving previous revisions.
What is Version Control
Version control (or revision control) is a system that manages and tracks changes made to files, sets of files, and directories. These changes are recorded as revisions with a timestamp followed by the person who made the change. Revisions can be reviewed, compared, merged or restored.
But how does a version control system benefit us? Imagine you are working on a web development project. When making changes to a particular file you want to keep track of the changes you made, or, slightly trickier, when working on a project simultaneously with co-workers who are using the same files as yourself. This is when you would use the ‘Save As’ function and end up with files like the following:
With a version control system, no longer will you need to duplicate files, become confused as to which file is the latest version, or have to manually maintain all these duplicated files. A good version control system will allow you to explore past file changes, who made which modifications and when; you can even restore it (or the entire project) to a previous revision. Even if there are bugs or issues arising from your project, you can quickly identify who introduced the issues and resolve them. Even lost or accidentally deleted files can be recovered.
Central Version Control Systems
Local version control systems are great for single user case scenarios but this becomes a problem for collaborative work. This is what central version control systems such as Subversion (SVN), CVS and Perforce were developed for.
Central version control systems are based on the concept that there is a single central location, most likely on a server, where the project is stored as a whole (including all versioned files). Developers and programmers would commit (save) their revisions to this central location.
With a central location, everyone can checkout the latest changes and can be sure that they have the most up-to-date files. With a single location for a project, administrators and collaborators can see what everyone is working on. Administrators can even restrict which users can do what by marking files and directories as off limits.
Advantages of Central Version Control Systems:
- No need to manually keep local copies of revisions
- Check in your latest changes to the central system, immediately see everyone else’s changes on the project
- You can always update to the latest working files
- Easy to collaborate in a team
- Ability to tag and branch on a project
Disadvantages of Central Version Control Systems:
- Single point of failure; if the central server repository is not available no one can pull down changes or commit their versioned changes
- Risk of losing everything; if backups are not regularly kept or when the server data corrupts, you could lose your entire repository of revisions.
- Depending on your network connection and where the central server is located, updating or committing your changes may take some time to complete
- Sometimes difficult to resolve conflicts or merging and reconciling changes from other branches
Distributed Version Control Systems
Over the past few years a new form of version control systems called distributed version control systems has emerged and has been quickly adopted by the web development community. The most popular of these include Git and Mercurial.
Distributed version control systems rely upon a peer-to-peer approach as opposed to a client to server model. It’s not necessary to have a central location to store all the versions of a project, instead developers and programmers copy (called clone) the main project to their local hard drive, so everyone has a physical mirrored copy of it to work on.
Should the original source (such as the server) fail, any of the cloned clients can be copied back up to the original server to restore all revisions. Since cloned clients have a full copy of the project, viewing revisions, saving revisions, or restoring changes are much faster because there is no need to communicate to a central server.
The act of simply receiving the latest updates is called ‘pulling’. Pulling allows the user to pull down most recent changes from a location. The act of distributing your revisions to the group is called ‘pushing’, the process of moving changesets (changes to file groups as coherent wholes).
With a distributed system, this opens up the possibility of having several remote repositories (the database storing the versioned files). This then enables you to work with different groups of people or different ways simultaneously.
Advantages of Distributed Version Control Systems:
- Faster to save your revisions compared to a central version control system because you are storing changes to your local hard drive rather than to a remote server
- Focuses on sharing changes
- Committing changes are done locally, so no one can see these changes unless you are ready to push them back to server
- You can work offline and only push and pull changes when you have an established internet connection
- Easy to branch and merge changes
- All cloned clients are essentially a full backup of the full project
Disadvantages of Distributed Version Control Systems:
- Steep learning curve for newcomers
- If the project is very large with a long history, cloning the project can take an impractical amount of time and disk space
Why should you use a Version Control System?
We’ve looked at how version control systems work and the options available to us, but what are the benefits of using a version control system? Let’s take a look at some of these:
- All files and directory changes are saved. This allows you to view any revision changes from any particular moment in time.
- No need to manually track file changes
- Restore any previous revision at any point in time
- Designed to help multiple people collaborate on a project
- Everyone in the team can be sure they are working with the most up-to-date files/directories and using the correct file and directory structure
- No more overriding someone else’s work whilst working with a team
- Share your work to a wider audience
- Branch off to work on a new feature or fix a bug without affecting the main branch
- Tag your releases for reference purposes
If you're interested in learning more, feel free to take a look at my other post which describes how version control works, or check out these free Git tutorials on the DeployHQ website.
We hope you've found this post useful in outlining the advantages of version control as well as the different options it can provide. If you have any questions please don't hesitate to get in touch.