SSH setup

If you have not already set up github with ssh access, do that first. Create a github account. Then check to see if you already have an ssh key or generate one if you don't (github has directions for this). Then go into your github account settings and add the contents of your id_rsa.pub file to the list of keys.

Initial checkout

Next, you must check out your directories from the repository. This will give you your own working copy of the files. You will receive a link to create your git respository. Once you do that, the "Clone or Download" button on the repository page will give you an ssh repository name. For a git GUI, use that when cloning the repository onto your local computer. Using the command line, you'd use a command like this

git clone repository_name_from_github directory_name_of_your_choice

This will create a directory with the name you chose containing a new working copy of your files. This is the only time you need to tell it where the repository is. After the initial checkout, once you cd into your working directory, Git can figure out which repository to use. All of the major git commands apply to the current directory and all directories under it.

Editing

Edit away... No need to do anything special

Adding, removing, and ignoring files

Ask Git about the files it doesn't know about yet

git status

You may see sections for files "Changed but not updated" (including files previously checked in that have been modified or deleted), and/or for "Untracked files". If there are any files listed that should not be checked in, edit the .gitignore file and add them to the list of files Git should not track. This includes any files generated when you build — if you didn't create it, you probably don't want to check it in. Once git status just lists the files that should be checked in, you have tell git that you really do mean to remove any that are marked to be deleted:

git rm file

Now tell git what other files you want to commit (for new or changed files)

git add file

This is called "staging" your commit. Now you can commit a local copy of your work. This is not yet submitted, but you can use these intermediate revisions to track your work and go back to prior versions. You should give a short but useful message that will identify the main content of this commit. For example, "Initial parsing code", or "Fixed cross-product bug", etc. All of the revisions committed in this way will be submitted when you later do a git push.

git commit -m "short message"

Getting updates and previous revisions

If I make any changes to the initial sample files (or add some for the later assignments), you can get these using

git pull

You can compare your current file with any previous version. This can be especially useful if something stops working that was. It is a good idea to commit often, especially before starting on any big changes.

git diff commit_ID

To figure out which commit IDs for comparison is which (assuming you entered reasonable log messages when you committed your changes), do

git log file

You can also select commits by date using a format like '@{1/1/05 13:15 EST}' for the commit ID

Submitting your changes

Your changes are not copied to the repository until you both commit them, and push them to the repository. To tell us which commit to grade, you should tag it with the assignment name.

You must do this for us to be able to check out and grade your work, but you can push your changes to github as many times as you want before then. Pushing your changes to the class repository before the deadline can help serve as a backup copy of your work, or allow you to work in multiple locations by copying changes to the main repository whenever you are done at one location before you move to the other. To push changes to the main repository, just do this:

git pull
git push

To tag which commit is your submission, either use the github web interface, or these commands (with the current assignment number instead of assn1):

git tag assn1
git push --tags

Learning more

List of all Git commands

git

Help on any one Git command

git --help command

And, of course, there are tons of resources on git online