Source Control: A Time Machine For Your Source Code

Posted By: Nick Floyd

What is source control and why should you use it?

Source control lets you keep every single version of your files. Over time your files change as you make modifications to them. If you’re working on a single file like a document, not tracking those changes is fine, but your source code needs to be tracked even if you are a lone developer. When you are developing an app, sometimes you start down a path that you think will be fruitful, but then you quickly discover that the implementation will not work as well as you thought it would. Using a version control system (VCS) allows you go back to the state of the code before you implemented the feature. Source control is like a time machine for code. If you want to go back, just look at the history and load up the code at that point in time. BY-NC-ND 2.0

Think of source control as your own personal time machine.

Another scenario where a VCS is extremely helpful is when you are working on a team, and you and a teammate are working in the same file. This is impossible without source control because when you save you might overwrite your teammate’s changes or vice versa. Without a VCS, this usually leads to naming files with some sort of version scheme (i.e. MyCode-20100322.cs, SharedClass-FINAL.cs, SharedClass-DONOTTOUCH.cs, and so on…) Instead VCSs recognize that the file has changed and lets you merge your changes in with your teammate’s changes ergo preserving both of your changes.

Whether you are in a team or a lone developer, you can benefit from using source control to manage your code. Source control systems also do not require a particular type of file. You can use a VCS to manage any type of file: Microsoft Word, HTML, images, text files, or even binaries. The merging capabilities are only useful with text based files, but the VCS can preserve the version of binary files.

How can you get started with Version Control?

How much would you pay for a sophisticated Version Control System? $200? $1,000? $40k? Although having such a great tool may be worth the money, the good news is that some of the best VCSs are free. Corporations and large organizations are using some of these free VCSs:

These applications are free as in they have no cost and as in you have rights to use them as you see fit. Git is the most versatile and the most popular VCS so I will cover it in this post, but feel free to investigate the others.

Git Basics

Git was originally created to be used on the command line, but there are a few graphical front-ends for git such as the included Git GUI and Git-cola. However you use Git, here is the basic usage for Git:

  1. Clone an existing Git repository (git clone)
  2. Add/modify files already added to the repository
  3. Stage the files that will be committed to the server (git add)
  4. Write a commit message that details your change.
  5. Commit to the repository.

That’s it. The changes are saved and you can review them later when you need to (using git log).

It’s worth noting that everything done has been without the need of an internet connection. One of Git’s strengths is that it sets up a local repository. This means that you can keep your changes tracked locally and it doesn’t require a connection to a central repository.

Working Remotely

Using Git you can collaborate with others using the push and pull feature. By setting up an external repository on another machine or a hosted repository like GitHub you can pass the URL of the repository to your friends, co-workers, team members, etc. and they can clone the repository and make changes locally and commit them back to the repository. The workflow for that looks something like this:

  1. Get a copy of the repository (git clone)
  2. Make your own changes (git add and git commit)
  3. Send them back to the server where you got them (git push)
  4. Get changes made by others (git pull)


Here are some resources to learn more about using git.

Jesse Dearing is a Developer for Fellowship Technologies.  He likes learning about new technologies and languages (especially ones that are used on the web) as well as learning about new trends and practices in software development.  He is passionate about software development and helping other developers.

Posted In: Tips,

iPhone 5 Release said: on July 30, 2011 at 03:21 AM

What do you believe are the advantages and disadvantages of a version control system?

iPhone 5 Release

Now You Comment

Remember my personal information.   |   Notify me of follow-up comments.


Previous Posts:

Subscribe to the RSS feed!