In this lesson, you will learn about the process and benefits of version control and how
GitHub support version control.
After completing this lesson, you will be able to:
- Define version control
- Explain how version control is useful in a scientific workflow
- Describe how
GitHubsupport version control
What You Need
Be sure that you have completed the lesson on Get Files From Github.com.
The text and graphics in the first three sections were borrowed, with some modifications, from Software Carpentry’s Version Control with
What is Version Control?
A version control system maintains a record of changes to code and other content. It also allows us to revert changes to a previous point in time.
Types of Version control
There are many forms of version control. Some not as good:
- Save a document with a new date (we’ve all done it, but it isn’t efficient)
- Google Docs “history” function (not bad for some documents, but limited in scope).
- Version control tools like Git, Mercurial, or Subversion
Why Version Control is Important
Version control facilitates two important aspects of many scientific workflows:
- The ability to save and review or revert to previous versions.
- The ability to collaborate on a single project.
This means that you don’t have to worry about a collaborator (or your future self) overwriting something important. It also allows two people working on the same document to efficiently combine ideas and changes.
Thought Questions: Think of a specific time when you weren’t using version control that it would have been useful.
- Why would version control have been helpful to your project & work flow?
- What were the consequences of not having a version control system in place?
How Version Control Systems Works
Simple Version Control Model
A version control system tracks what has changed in one or more files over time. Version control systems begin with a base version of a document. They then save the committed changes that you make. You can think of version control as a tape: if you rewind the tape and start at the base document, then you can play back each change and end up with your latest version.
Once you think of changes as separate from the document itself, you can then think about “playing back” different sets of changes onto the base document. You can then retrieve, or revert to, different versions of the document.
Collaboration with version control allows to users to make independent changes to the same document.
If there aren’t conflicts between the users’ changes (a conflict is an area where both users modified the same part of the same document in different ways) you can review two sets of changes on the same base document.
A version control system is a tool that keeps track of these changes for us. Each version of a file can be viewed and reverted to at any time. That way if you add something that you end up not liking or delete something that you need, you can simply go back to a previous version.
Git and GitHub - A Distributed Version Control Model
Git uses a distributed version control model. This means that there can be many copies (or forks/branches in
GitHub world) of the repository. When working locally, git is the program that you will use to keep track of changes to your repository.
GitHub is a location on the internet (a cloud web server) that acts as a remote location for your repository.
GitHub provides a backup of your work, that can be retrieved if your local copy is lost (e.g., if your computer falls off a pier).
GitHub also allows you to share your work and collaborate with others on projects.
How Git and GitHub Support Version Control
In the lesson on Open Reproducible Science, you learned that
Git is version control tool that you use in the
Terminal to work with and track changes in local files. You also learned that
GitHub is the cloud-based version of
Git, which can be used to store your files (as well as changes to those files) in the cloud to access them from any computer and to share them with others.
Due to the functionality that each tool provides, you can use
GitHub together in the same workflow to:
- keep track of changes to your code
- synchronizing code between different versions (i.e. either your own versions or others’ versions)
- test changes to code without losing the original
- revert back to older version of code, if needed
- back-up your files on the cloud
- share your files on
Github.comand collaborate with others
Throughout this course, you will learn more about the functionality of
GitHub and how they support transparency and reproducibility in workflows, which in turn promotes open reproducible science.