Skip to the content of the web site.

The git version-control system

IEEE Spectrum Magazine    MIT Technology Review    Wired Magazine    EDN Network    EE Times    Skeptic's Guide to the Universe

Authors: Douglas Wilhelm Harder and Prof. Hiren Patel

A quick introduction to version control

If you already have an idea about what version control is, you can skip directly to git.

Suppose you are working on a project or have partially written an essay. You're happy with what you have up until now, but you'd like to try something different. Never-the-less, you'd like to keep a copy of your current project so that if your changes don't work, you can come back to it.

The simplest solution is to copy the current project to a new name: call it project_3_old.cpp. If you need another one, you can call it project_3_old2.cpp, and so on and so forth. If it is a large project, you might end up with a directory filled with older copies:

     project_3.cpp          project_3_old.cpp       project_3_old2.cpp
     project_3_old3.cpp     project_3_old4.cpp      project_3_old5.cpp
     project_3_old6.cpp     project_3_old7.cpp      project_3_old8.cpp
     project_3_old9.cpp     project_3_old10.cpp     project_3_old11.cpp
     project_3_old12.cpp    project_3_old13.cpp     project_3_old14.cpp

Your next thought is you might want to time stamp the copies so that you know when you made them, so instead you now have:

     project_3.cpp
     project_3_old_Sept19.8pm.cpp
     project_3_old_Sept18.9pm.cpp
     project_3_old_Sept18.7pm.cpp
     project_3_old_Sept18.9am.cpp
     project_3_old_Sept16.10pm.cpp
     project_3_old_Sept16.8am.cpp
     project_3_old_Sept14.5pm.cpp
     project_3_old_Sept11.2am.cpp

This is frustrating, as you don't know what the significance of these copies are. Sure, when you made the copy, you knew exactly why you wanted to keep a copy, but even one week later, you'll be wondering which copy contains what changes. Thus, you decide it would have been better to add a note you can easily see:

     project_3.cpp
     project_3_old_Sept19.8pm_going back_to_arrays.cpp
     project_3_old_Sept18.9pm_next_three_functions_working.cpp
     project_3_old_Sept18.7pm_retrying_linked_list_successful.cpp
     project_3_old_Sept18.9am_next_two_functions_working_and_tested.cpp
     project_3_old_Sept16.10pm_tried_using_heap_does_not_work.cpp
     project_3_old_Sept16.8am_first_four_functions_working_and_tested.cpp
     project_3_old_Sept14.5pm_used_recursive_algorithm.cpp
     project_3_old_Sept11.2am_tried_linked_list.cpp

Suppose you want to try using a heap again. What happens now? You'd have to manually look at the changes you made between the version from September 16 at 8 am an the one at 10 pm. You would have to manually determine the changes to the files.

Version control to the rescue

Version control programs do all of this for you, but have added bonuses, they

  • hide the older versions but allows you to easily access them,
  • allow you to go back and forth between version you are working on,
  • determine the differences between the versions, so if a change you made introduces a bug, you can more easily deduce what may have introduced the bug,
  • allows you to share your code with others (although you should not do this in your programming course),

and many other benefits.

One of the most popular version-control systems today is git; consequently, we will introduce that version. Another excellent version-control systems include Perforce.

git

We do not teach version control in this course; however, we do offer some suggestions as to how you can learn to use the git distributed version-control system. To learn about how git works, please consider the following excellent visual on-line learning tool:

Learning Git Branching.

This resource is provided by the JavaScript developer web site JS.org. This provides a step-by-step visual walk through using git.

EngSoc also occasionally puts on workshops where they teach you how to use git.

A web-based interface for git is the web site GitHub.com. GitHub provides the git with a graphical user interface provided by a web browser.

Fortunately, the best tool for learning GitHub is available on that site at the GitHub Learning Lab.

There is a local University of Waterloo gitlab.uwaterloo.ca.

WARNING: Do not put your source code in a publicly visible repository. If another student finds your source code and copies it, you are responsible, and you will receive a grade of 0 on that project and a -5% penalty on your final grade. GitHub does offer unlimited private repositories to free accounts. If it is your intention to demonstrate your command of the C++ programming language to potential co-op employers, be sure to make use of a private repository.