A version control system is a special application that stores and manages every revision of your files and code. Many developers and organizations use version control to collaborate on source code, manage releases, and roll back to previous versions when bugs are discovered.
Setting up a version control system is easy. The hard part is learning to use it, and then incorporate it in your daily workflow. This section introduces version control and explains how you can apply it to your own projects. We’ll walk you through all of the steps, from evaluating the different version control systems to creating and using a repository.
Why Use Version Control?
If you host a website or web-based application on your Linode, your users rely on your content to be available. You also need to keep your content updated and patched. However, changing your content can result in unforeseen bugs, which in turn can result in downtime. You need a way to protect your code and files through changes, to test updates before they go live, and to roll back to a working version if something goes wrong.
Version control (also referred to as revision control or source control) is a file storage system that tracks every change made to a file and allows you to reverse or roll back those changes. For example, if you were editing a file on your personal computer and decided to delete a section of code, you could use version control to restore that section of code in the future – even weeks or months from now.
Version control is also a great tool for individuals who need to work on the same files at the same time. With version control, they can check out the repository and then commit the changes when they’re finished. If two individuals have modified the same file, the version control system can usually merge the changes, unless there’s a conflict, in which case the user will need to manually combine the changes or favor one change over the other.
Version control also makes it easy to track changes. You can see who committed code, and why. And if you start working on a new version of your website or application, you can branch a copy of your code to a separate area. (The branch can later be modified back into the trunk.) In short, version control is cheap insurance against human errors and unforeseeable disasters. You should be using it!
Example Version Control WorkflowPermalink
This is the process most developers use to create, stage, and commit files to a Git repository. It could be different than the process you’re currently using, but it’s important to learn Git’s workflow and at least try using it, even if it seems a bit weird at first. Here’s how it works:
Create or modify files in your working directory. Once you’re satisfied with your changes, use the git add command to move the modified files to the staging area.
Snapshots of the new and modified files are added to the staging area. Now you can preview the files.
When you’re ready to commit the files to the repository, use the git commit command. The files in the staging area are permanently stored in your Git directory.