Using Git to submit assignments

Initial checkout

First, you must check out your directories from the repository. This will give you your own working copy of the files. Do not attempt to work directly in the repository, and we probably won't be able to check out your code to grade it. On the GL systems, you'd use a command like this

git clone /afs/ directory_name_of_your_choice

For example, if you were in 435 and your username was xyzzy, you might do this:

git clone /afs/ cs435work

This will create a directory called cs435work containing a new working copy of your files. This is the only time you need to tell it where the repository is. After the intial 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.


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.

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

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. You must do this for us to be able to check out and grade your work, but you can do it 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 to the main repository, just do this:

git pull
git push

Learning more

List of all Git commands


Help on any one Git command

git --help command

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