We will be using Git, and GitLab, to manage the homework assignments, and we will later use GitHub to manage to final class project.
We will discuss key functionality of version control systems, mostly in the context of a particular such system called Git, which is used to maintain a huge number of popular projects. While most version control systems have similar capabilities, their terminology tends to vary.
A version control system typically offers the following functionalities:
You can identify a set of changes to your code as a single item, called a commit. This allows you to put together related changes into one.
Each commit incrementally builds upon some previous commit, creating a tree of commits. This is known as a repository. Many websites like GitHub, GitLab and others, allow you to store and manage these repositories online, allowing teams from all over the world to collaborate. They also on occasion offer automatic web-page hosting. In fact the page you ar reading right now is published via a GitHub repository.
The system comes built in with tools that allow us to do many things:
A branch is a pointer to a particular leaf on this tree that carries a particular meaning to us. In effect, a branch points to a particular view of our codebase.
We typically advance our code by making a new commit at a leaf, advancing the branch pointer at the same time. We can easily switch from one branch to another, completely changing the contents of our project directory.
New branches are easy to create and delete, and can be used for many reasons:
master
branch typically represents the main working part of our code base. This is where stable additions can be made to our code.experimental
branch can be used to try out a new idea, without destroying our main code base.stable
branch can contain the last stable release of our project, while we dedicate another “main” branch to work towards the new version of our application. If an urgent fix is needed, we can switch to this stable branch and apply the fix, then go back to working on the main branch.deploy
branch may contain specific setting used for deploying an application. We can merge the main branch into the deploy branch when we are ready to deploy our next release.Repositories are typically stored in a remote server. We create a clone of a repository on our computer in order to work on it. This clone contains both local branches, that we create to do our work before sharing it with the world, and also remote branches that are exact replicas of the branches in the remote repository.
Oftentimes a project deviates from its original. In our case, for the homework assignments, each student would be starting from an initial repository that the instructor creates, but then follow completely different paths with their solutions, that they each own and do not want to share with others. These are called forks, and the way to accomplish that is essentially for each student to create a copy of the repository on their own remote repository, that only they and the instructor have access to. They can then work at will with that repository and completely independently of the other students. So a fork is a new remote repository which was created as a spin-off of an existing remote repository in order to support independent development of the project in a different direction than the original.
If you have not set up Git on your account before, you may need to do these steps:
First we should make sure the system knows your name and email, to use in commits. These would typically be set by running the following:
git config --global user.name "yournamehere"
git config --global user.email "youremailhere"
Make sure to use the same email that you plan to use for your online git repositories, that we will be creating shortly.
GitLab is an online hosting service for git repositories. It also offers project-management functionalities, for example you can organize your project work by creating issues, milestones, assigning tasks to users, labeling issues and so on.
Further instructions are part of the second assignment.
We describe here the typical steps when making commits. A commits consists of two steps: