This is not the current version of the class.

GitHub setup

We use git with GitHub Classroom for version control, problem set submissions, and code distribution. Git is a distributed version control system. “Version control” means Git tracks the history of changes to a set of files; “distributed” means it allows repositories to synchronize with each other in a peer-to-peer fashion, rather than blessing one centralized repository as the source of all truth. Linus Torvalds initially developed Git for use with the Linux kernel. It’s the best widely-available version control system, and certainly the most widely used. For information on how to use git, see:

The rest of this page explains how to set up GitHub for use with CS 61.

Create a GitHub account

You will submit your code by pushing it to GitHub, and every CS 61 student should have a GitHub account. Many actions on GitHub will require authenticating yourself—proving that you have access to your repositories—and the best way to do that involves an SSH key, a secret key that defines your identity, and an SSH agent, a program that remembers the identity so you don’t have to type your password all the time. Here’s how.

  1. Create a GitHub account if you don’t have one already.

  2. Create and/or configure an SSH key using GitHub’s instructions. Specifically:

    • Create the key (if you don’t have one already) using the ssh-keygen program.
    • Add the key to your GitHub account.
    • Test your SSH connection.

About SSH identities. An SSH identity is stored in two files, a public key with a name like /Users/yourname/.ssh/id_ed25519.pub and a private key with a name like /Users/yourname/.ssh/id_ed25519. The private key is kept secret—you should never upload the private key to a shared service—while the public key can be uploaded anywhere you like, including your GitHub account. The public and private keys are a matched pair. Services like GitHub verify your identity using a mathematical protocol: your computer essentially proves that it has access to the private key corresponding to your public key, after which GitHub “knows” that your computer speaks for you.

If you use multiple computers to do your problem sets, you’ll need to configure an identity on each of these computers. You can do this either by creating and configuring multiple SSH keys (this is probably a little safer), or by copying the public and private keys between the computers (this is probably a little easier, though it’s important to get the file permissions correct).

The CS 61 Docker configuration should forward identity requests to your main computer, so once your SSH connection works on your main computer, it should work inside Docker too. However, if you use a VirtualBox or VMware virtual machine, you will need to set up an SSH identity on that virtual machine.

Configure Git

You should also tell your Git installation your name and email, if you haven’t already. This will ensure that you are recorded as the author of your code. For the user.email configuration, use your Harvard email.

$ git config --global user.name "FIRSTNAME LASTNAME"
$ git config --global user.email "YOUR@EMAIL"

Terminal sessions: A display like this represents a terminal session. To run the commands, you will open a terminal on your computer and then type (or copy and paste) each bold line into the terminal window, one at a time, pressing Return to run each command before going on to the next. The gray $ characters represent shell prompts and should not be copied, and blue lines represent command output.

Create your problem set repository

We’ll release starter code for problem sets via the cs61-f23-psets repository. However, you will want your own private GitHub repository for problem sets, so that you can save and submit your own solutions code. You’ll clone that private repository onto your computer, do work there, and then push your work upstream to GitHub for us to grade. Here’s how to create that private repository.

  1. Visit our GitHub Classroom link: https://classroom.github.com/a/ctXutQ03

    • Log in if prompted.

    • Accept the assignment. This will create an empty repository with a name like cs61/cs61-f23-psets-YOURUSERNAME.

    • Refresh the page until the assignment repository is ready.

  2. Create an local copy of your (initially empty) repository.

    • Visit your repository’s web page, which will have a link like https://github.com/cs61/cs61-f23-psets-YOURUSERNAME

    • Copy the repository’s SSH link, which will look like git@github.com:cs61/cs61-f23-psets-YOURUSERNAME.git

    • Clone the empty repository to your computer.

      $ git clone git@github.com:cs61/cs61-f23-psets-YOURUSERNAME.git
      Cloning into 'cs61-f23-psets-YOURUSERNAME'...
      warning: You appear to have cloned an empty repository.
      
  3. Add a remote to your repository for our handout code. This will use Git’s distributed features to allow you to merge our updates with your code.

    $ cd cs61-f23-psets-YOURUSERNAME
    $ git remote add handout https://github.com/cs61/cs61-f23-psets.git
    

    This command creates a new shorthand name, handout, for our handout code repository.

  4. Merge our latest handout code with your repository.

    $ git pull handout main
    remote: Enumerating objects: 9, done.
    remote: Counting objects: 100% (9/9), done.
    remote: Compressing objects: 100% (9/9), done.
    remote: Total 9 (delta 0), reused 9 (delta 0), pack-reused 0
    Unpacking objects: 100% (9/9), 5.23 KiB | 669.00 KiB/s, done.
    From github.com:cs61/cs61-f23-psets
     * branch            main       -> FETCH_HEAD
     * [new branch]      main       -> handout/main
    

    This command loads our current handout code and then merges it into your repository. You’ll run something like this every time we release or update a problem set.

  5. Store the resulting code in GitHub so you don’t lose work.

    $ git push
    Enumerating objects: 9, done.
    Counting objects: 100% (9/9), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (9/9), done.
    Writing objects: 100% (9/9), 5.25 KiB | 2.62 MiB/s, done.
    Total 9 (delta 0), reused 0 (delta 0), pack-reused 0
    To github.com:cs61/cs61-f23-psets-YOURUSERNAME.git
     * [new branch]      main -> main
    

    If you visit the Web page for your private GitHub repository, you should now see our handout code.

You can invite other students or TFs to see your code using the repository’s Settings > Manage access. Remember, though, that you must not share your solutions in a public place.

Clone the lecture repository

We’ll release code and writeups for lectures via the cs61-lectures repository. You’ll want a local clone of this repository so you can play with the code yourself, and it’s easy to create one.

$ git clone https://github.com/cs61/cs61-lectures
Cloning into 'cs61-lectures'...
remote: Enumerating objects: 456, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 456 (delta 0), reused 7 (delta 0), pack-reused 449
Receiving objects: 100% (456/456), 137.36 KiB | 2.18 MiB/s, done.
Resolving deltas: 100% (205/205), done.

This creates a directory cs61-lectures with a copy of the lecture code.

Troubleshooting

If you are having any trouble with your keys (e.g., you cannot clone a repo because the connection “timed out”), check if your firewall is blocking port 22, and open port 22 if it is blocked.