Setup for Swarthmore GitHub


One-time git / GitHub configuration

Before using Swarthmore's GitHub Enterprise, you'll need to complete the following configuration steps once (run from our system). If you have done this for another Swarthmore CS class, you do not need to create a new key, but please check that the key file exists in your .ssh directory and is listed on your Swarthmore Github account.


1. Create an ssh key

SSH (Secure SHell) is a mechanism that allows you to interact with remote machines and issue commands to them. It typically uses a username and password, but in some cases (and this is one of them), you need something else: a cryptographic key.

NOTE: You need to create your ssh key's on the CS system. Log into one of the cs lab machines and follow these steps:

If you already have an ssh key, you can skip this step. If you're not sure, you probably do not already have a key. You can check by issuing the command:

ls -l -a ~/.ssh

If you see files named id_rsa and id_rsa.pub, you already have a key. If those files aren't there, or you're told that you have no such directory named .ssh, you'll need to generate a key.

GitHub has a good comprehensive guide on the subject, but I'll give you the executive summary below:

Run the command ssh-keygen. This will give you the output:

 $ ssh-keygen
 Generating public/private rsa key pair.
 Enter file in which to save the key (/home/[username]/.ssh/id_rsa):

Press enter to confirm the default location of /home/[username]/.ssh/id_rsa. Next, it'll ask you for a passphrase:

 Enter passphrase (empty for no passphrase):
 Enter same passphrase again:

Set a passphrase that you'll remember and then confirm it a second time. After confirming your passphrase, it'll print a key fingerprint and some strange abstract ASCII artwork that you can safely ignore.


2. Log in to Swarthmore's GitHub Enterprise and add your key.

Next, we need to let GitHub know about this key we just created. In your browser load: https://github.swarthmore.edu and log in using your typical Swarthmore account credentials (same account you use for email). It may ask for your name, email address, or other information. Fill that in.

When you're properly logged in, click the small gear icon at the top right of the page to get to your account settings. Choose SSH Keys from the menu on the left. Click the Add SSH key button, and two boxes will appear. Fill in the name with anything you like, this is just to help you remember where you generated the key. I would suggest a name like CS account.

After you've named your account, you need to copy in the entire contents of the id_rsa.pub file that you generated earlier. Make sure you use the file ending in .pub. You can dump the contents of the file by executing:

 cat ~/.ssh/id_rsa.pub

Copy the entire output of that file, paste it into the Key box on GitHub, and click Add Key.


3. Git client user configuration settings

Before you starting using the git command on the command line, you need to give it a basic configuration. This will tell git who you are, making it easy for you and your partner to identify who committed code to your shared repository.

Replace the email and name strings with your email address and name. If you have not run these commands, then the very first git commit will fail and tell you to run them.

From the unix command line, run:
git config --global user.email "username@swarthmore.edu"
git config --global user.name  "Your Name"

Once you have done these steps, you can access your lab git repos


Using your git repository


Cloning a local copy of the lab repository

With git, you (and your partner) cab create a local copy ("clone") of the shared repository, make and commit changes locally, and push the changes back to GitHub, where your partner can retrieve them.

Click on a repository, and it'll take you to a page that lists its contents (and many other useful things). One the lower right hand side, you'll see some text that says "You can clone with HTTPS, SSH, or Subversion". Click the "SSH" link. This will give you a link that you can use to clone. Let's first enter our cs31 directory and make the clone there:

    cd
    cd cs##/labs

From here, you can use git clone [URL] to locally clone the repository, where [URL] is the SSH URL given to you by GitHub. For example, if Bryce were cloning, he might use: "git clone git@github.swarthmore.edu:cs31-f16/lab00-bwieden1.git". You can now cd into your repository directory and access the files there.


Using your shared repo

At this point, you now have a master git repository for your project that only you, your partners, and graders/instructors can access. All changes, additions, deletions, to this project can be done with git commands that will push and pull changes from this remote master copy.

You and your partner will work in your local private copies of the repo. You can add and commit changes to your private copy as you go, and choose when to push your change to the remote master repo. Once you push changes, your instructor or partner can then pull from the remote master into their copy.

An example of a sequence of common git commands:

 # check the status of your repo
 $ git status

 # see the changes to the file (compared to your last local commit):
 $ git diff blah.c

 # add a new file to the repo on the next commit:
 $ cp ~/private/foo.c .
 $ git add foo.c
 # or add new changes to an existing repo file to the next commit:  
 $ vi blah.c      # edit with your favorite editor
 $ git add blah.c  

 # commit your changes (adds and deletes) to your local repository:
 $ git commit

 # push committed changes from your local to the remote master repository
 #  note: the first time you push, you may need to do:
 #        git push origin master
 $ git push

 # your partner can now pull your changes from the remote into their local:
 $ git pull