Version Control

One major practical problem facing programmers is version control: keeping track of the code they write. Here are some of the reasons this can be challenging:

As one can imagine, this is an extremely complex problem without any single answer, but luckily with the help of some smart people the majority of the programming world has converged towards one solution — Git.

Git was a project initially started by Linus Torvalds - the father of modern day Linux - when he felt that existing code-sharing tools were insufficient and approached the problem in the wrong way.

You probably already have experience with saving your work as you go. One is to “Save As” every so often and put your document in a new file with a modified file name like “Term Paper June 13 draft 2 (revised, need to add tables).” This is good for keeping snapshots of the work as it existed at different points in time. But the names can get unwieldy unless you’re very disciplined about what names you choose, and this approach is harder to make work well when you have multiple files (maybe a paper, a related presentation, and a bunch of images included in both).

This is how Git works, more or less. Whenever you reach a good point to pause your work, you can take a snapshot of the project, called a “commit.” Each commit represents the entire project as it exists at one specific moment in time. As you keep working, you add more commits, and Git remembers them all — for all practical purposes, Git never throws away the work you had stored in a commit. At any point, you can rewind the project to a previous commit. It’s like being able to hit “undo” and “redo” as often as you want for an entire project.

The other fundamental Git concept is the “repository.” A repository is Git’s entire history for your work on a specific project: it stores all of the commits for that project. In this course, we’ll have you set up separate Git repositories for each assignment. You can think of a repository as a special folder on your computer: once you tell Git to treat that folder as a repository, Git keeps track of all changes to files in the folder.

Remote Repositories and GitHub

One reason Git is popular is that it makes it easy to connect the Git repository on your computer (a “local” repository) to a Git repository on another computer (a “remote” repository). You can “pull” commits from the remote repository into your local repository, and “push” them from your local repository to the remote repository, keeping the two in sync.

Syncing with a remote repository turns out to be a great way to distribute software. If you want a copy on your computer, you can pull from a remote repository into a local one, and voila, you have a copy. It also turns out to be a great way to collaborate. If multiple programmers connect their local repositories to the same remote repository, they can push their own commits to the remote and then pull each others’ commits from the remote, keeping everyone in sync. In this course, we’ll also use remote repositories in a third way: you’ll submit your homework by pushing a commit to a “private” remote repository just for you and the course staff.

Programmers can (and do) use lots of different remote Git repositories. But one especially popular host for them is GitHub, a private company which provides a convenient place to store the remote Git repositories. GitHub is free to use in many settings (including public repositories that anyone can see and most educational uses). Remember: Git is the software you run on your computer to handle the committing, merging, pulling, and pushing, while GitHub is the website you will use for your remote repositories.

Register on GitHub

The easiest way to install Git is via GitHub’s tools, so we’ll start there. If you already have a GitHub account, great, skip over this!

Open GitHub Register

GitHub Desktop Second Screen

Choose the free, unlimited public repositories plan.

Register2

For the remaining questions/steps, simply skip through them (or fill them out if you feel like it).

Register3

Congratulations! You are now registered for GitHub!

Installing Git

Now let’s install Git on your computer.

For this course we recommend using an app called GitHub Desktop that provides a convenient graphical view of your repositories.

To install GitHub Desktop (which includes Git), open the following link: GitHub Desktop and press the “Download” button. On macOS, you will get a file called “GitHubDesktop.zip”. Double-click on it, which will give you a file called “GitHub Desktop.app.” Drag that file (with a nice purple icon) to your Applications folder. On Windows, you’ll get a file named “GitHub Desktop”. Double-click on it, then click “Install” in the pop-up window.

Once the program is installed, start GitHub Desktop, and you will be greeted with the following:

GitHub Desktop First Screen

Proceed to chooose sign-in with GitHub.com account, and sign in with the account you created during the set-up steps.

GitHub Desktop Second Screen

Proceed through the questions/customizations (leave everything as-is) until you reach this page:

GitHub Desktop Roll

Congratulations! You now have a basic but complete “toolchain” on your computer: everything you need to write and run code like a pro.