Caltech Gitlab Access

All assignments for this course will require you to submit one or more files as part of the assignment. Additionally, for some of the assignments, we will provide various supporting files for you to use as well. To simplify this process, and to make it easier for you to submit your work, you will complete each assignment in its own Git repository. All of these repositories will be hosted on the gitlab.caltech.edu server.

To get a Git repository for Lab 1, you need to go to this URL and register for the assignment:

https://grinch.caltech.edu/register

From this point forward, you will start every assignment using this registration tool, which will set up a repository for you and then send you an email with the repository information.

SSH Key Access

To clone and work with course repositories from the command-line, you will need to set up an SSH key-pair on the gitlab.caltech.edu server. If you already have an SSH key-pair for the computer you are working from (e.g. because you took another class that uses this server, like CS2, CS3 or CS24), then you can skip this step. (If you are unsure, you probably don't.) You can run this command on most Linux and Mac systems to generate a key-pair for your computer:

ssh-keygen -o -t rsa -b 4096 -C "my caltech gitlab ssh key"

The -C argument specifies a "comment" to associate with the key-pair; you might use your IMSS username, or you might want to indicate the specific computer or virtual machine you are working from. You may not want to mention a specific class, since this server is used for multiple courses, and you may encounter it again.

When you run this command, it will prompt you for several pieces of information; just accept the defaults for all of them. You can leave the passphrase blank if you wish.

This command will generate two file, ~/.ssh/id_rsa (the private key) and ~/.ssh/id_rsa.pub (the public key). The private key must never be shared. It's private, after all. The public key, however, can be shared with others; this is what you will input into the Caltech Gitlab server.

Navigate to this web page (which will require you to login using your IMSS username):

https://gitlab.caltech.edu/profile/keys

Paste the contents of your newly-generated ~/.ssh/id_rsa.pub file into the text field, then click "Add Key". Now you should be able to access the Caltech Gitlab server from your computer, using that key-pair.

Cloning the Repository

In general, you will want to have a specific location where you keep all of your work for the course. Recall that you will have one repository per assignment. You may want to create a "cs11-cpp" directory, for example.

You can clone the repository using a command like this (replacing "username" with your username, of course):

git clone git@gitlab.caltech.edu:cs11cpp-20sp/lab01-username.git

If you successfully completed the SSH key configuration steps, this command should result in the creation of a new lab01-username directory containing the files for Lab 1. This is actually a local clone of the repository on the Caltech Gitlab server, which means you can work against that local repository, and when you are ready to save your changes back to the server, you can "git push" them.

Git Workflow

As you make changes to your files for Lab 1, you will periodically want to commit them into the local repository you are working on. This is a multi-step process in Git, involving these commands:

git status       - shows modified files, and what is in the "staging area"

git add file.txt - adds file.txt to the "staging area" containing
                   files to commit

git commit       - commits all files in the "staging area" into the
                   local repository

In other words: The "staging area" contains files you actually want to commit. To add files to this staging area, you use the "git add file.txt" command. To actually commit them, you use the "git commit" command.

If you want a shortcut: "git commit -a" will always commit all files you have changed. This will likely be what you want to use most of the time.

Pushing Your Commits

When you have finished working on a given assignment, or when you want to make a backup of your work to the Caltech Gitlab server (do this often!), you can run the command "git push", which will push all local changes to the gitlab.caltech.edu server. This will also kick off any automated tests associated with the assignment, so that you can see if your code passes the automated tests or not.

Don't forget to push all of your commits when you have completed the assignment! You can always type "git status" to see whether you have properly committed your work, and whether your local repository is in sync with the Caltech Gitlab server.

Additionally, it is a good idea to push regularly, so that your work is backed up somewhere else, if your computer dies at an inconvenient time.

Got Questions?

Git is a very sophisticated version control system, and the above details only scratch the surface of its capabilities. Don't be surprised if you run into issues or have questions along the way; if you do, please ask for help! We will be happy to help resolve any issues you encounter.