Lab #0.5: Git & Chisubmit¶
You must be logged into a CS server using
NoMachine (the vDesk app), or
ssh to do this lab.
Learn the basics of git
Learn how to use chisubmit, our submission software
Git is a system used for developing software in a group. This system maintains files and all changes that are applied to them. You will each have a personal Git repository that is hosted on a central server. The server stores the project files and stores all changes to those files that have been uploaded to the repository.
We have created accounts and repositories for each of you on a CS department Git server. We will seed your repositories with templates and files that you need for your class work. Also, we will be able to see any changes you upload to your repository, which allows us to provide help remotely and to grade your programming assignments.
Git tracks every version of a file or directory using commits. When you have made changes to one or more files, you can logically group those changes into a “commit” that gets added to your repository. You can think of commits as “checkpoints” in your work, representing the work you’ve done since the previous checkpoint. This mechanism makes it possible to look at and even revert to older versions of a file by going back to your code as it was when you “checkpointed” it with a commit.
Git is a complex system that you will learn about over time. In this course, we will stick to the basics. Your workflow will be as follows:
Log into a CS machine using vDesk, NoMachine, or ssh.
Change to your
cmsc12100-aut-20-usernamedirectory, which you created in Lab #0
Download updates from the Git server (we will add files to your repository throughout the quarter). In Git, this operation is called pulling from the server.
Work on your files
Create a commit with any changes you have made
Upload the commit to the Git server. In Git, this operation is called pushing to the server.
The course staff does not have access to any files stored in your home directory or files on your laptop. All we can access are files that have been pushed to the Git server, so remember to always push your latest commits when you’re done or when you ask a question on Piazza that will require us to look at your code.
Please note that for this lab, indeed, for the rest of the quarter,
username should always be replaced with your CNetID.
Setting up your repository¶
If you have not already done so, make sure to follow the instructions under
“Setting Up Your CMSC 12100 Directory” in Lab #0. This will result in the
creation of a
cmsc12100-aut-20-username directory which will contain
your Git repository.
The rest of the lab requires you to have some modified some files. If
you have worked through all of Lab #0, you have already modified the
files we need you to modify. If not, make sure to do the following
with the files contained in the
Firstname Lastnamein the file
test.txtwith your name
NAMEshould be replaced with your name)
Recall that you can use the Linux
less commands to look at the
contents of a file to check whether you made these changes in Lab #0.
Creating a commit¶
Creating a commit is a two-step process. First, you have to indicate
what files you want to include in your commit. Let’s say we want to
create a commit that only includes the
hello_world.py file that
you just modified. We can specify this operation explicitly using the
git add command from the Linux command-line:
$ git add hello_world.py
(Recall that we use
$ to indicate the Linux command-line
prompt. It is not part of the command.)
There are various shortcuts that will allow you to add all of the
files in a directory, such as
git add . or
git add --all.
Using these commands is poor practice, because you can easily end up
adding files that you did not intend. Instead, it is better to add
files explicitly (as shown above) when you create them and then use
the following command:
$ git add -u
when you want to add any previously-added file that has changed since your last commit.
To create the commit, use the
git commit command. This command
will take all the files you added with
git add and will bundle
them into a commit:
$ git commit -m"Made some changes to hello_world.py"
The text after the
-m is a short
message that describes the changes you have made since your last
examples of commit messages might be “Finished part 1 of the programming assignment”
or “Finished lab 1”.
If you forget the
-m"Comment" at the end then Git will think that you
forgot to specify a commit message. It will graciously open up a default
editor so that you can enter such a message. You may be taken to
either a Vim editor or a nano editor. If you are not comfortable using
these text-based editors, please see I didn’t specify a commit message, and now I’m in a screen I don’t know how to get out of in our
FAQ for instructions on how to exit the editor, and then re-run
git commit with the
Once you run the above command, you will see something like the following output:
[master 99232df] Made some changes to hello_world.py 1 file changed, 1 insertion(+), 1 deletion(-)
You’ve created a commit, but you’re not done yet: you haven’t uploaded
it to the server. Forgetting this step is a very common mistake, so
don’t forget to upload your changes. You must use the
command for your changes to actually be uploaded to the Git
server. If you don’t push your commit, the instructors and graders will not be able
to see your code. Simply run the following command from the Linux
$ git push
You should see something like this output:
Counting objects: 7, done. Delta compression using up to 16 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 452 bytes, done. Total 4 (delta 1), reused 0 (delta 0) To email@example.com:cmsc12100-aut-20/username.git c8432e4..99232df master -> master
You can ignore most of those messages. The important thing is to not see any warnings or error messages.
You can verify that our Git server correctly received your commit by visiting the following page:
username should be replaced by your CNetID.
This URL takes you to the web frontend of our Git server (please note that you will have to log in using your CNetID and password). More specifically, the above URL will show you the contents of your repository, exactly as it appears on the Git server. You can click on “Files” to see your repository’s files, and on “Commits” to see the latest commits uploaded to the server. If you see a commit titled “Made some changes to hello_world.py”, then your commit was successfully uploaded.
In general, if you’re concerned about whether the graders are seeing the right version of your code, you can just go to the above URL. Whatever is shown on that page is what the graders will see. If you wrote some code, and it doesn’t show up in the above URL, make sure you didn’t forget to add your files, create a commit, and push the most recent commit to the server.
Pulling changes from “upstream”¶
When we distribute new course materials, we will do so through
Git. These files are located in a separate repository on our Git
server, which we call the “upstream” repository. The setup script you
ran earlier already configured your Git repository so you can easily
download any new files we upload to the upstream repository). To
download these changes, run this command from inside the
$ git pull upstream master
Run this command now. You’ll likely see something like this output:
From git-dev.cs.uchicago.edu:cmsc12100-aut-20/cmsc12100-aut-20 * branch master -> FETCH_HEAD Already up-to-date.
If we had changed a file between when you ran the setup script and when you ran this command, you might have seen something like this output:
Updating e73ccd2..5cc9de1 Fast-forward grader.py => common/grader.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename grader.py => common/grader.py (100%)
When you pull from “upstream”, Git automatically downloads any new files or changes that have been committed to “upstream” and updates the files in your repository. If you have made local changes to files that have changed upstream, Git will attempt to merge these changes.
After you’ve pulled from upstream, any new files or changes will only
be downloaded to your local copy of
with any other changes to your code, you need to run
git push to
upload them to the Git server (you don’t need to do a
to prepare a commit, though;
git pull already takes care of this
Every time you work on your code, you should run
git pull upstream
master in your
cmsc12100-aut-20-username directory before you
do anything else. Sometimes, the instructors notice typos or errors
in the code provided for an exercise or programming assignment, and
they’ll commit fixes to upstream. By running
git pull upstream
master, you can make sure that those fixes propagate to your code
Pulling changes from the server¶
Your instructor and the teaching assistants have access to your repository. Imagine that one of us made a change to your repository and pushed it to the server. How would you integrate those changes into your local copy of the repository? You will pull them, Specifically, you will run:
$ git pull
from inside your
It is important that you commit your changes after every session and
git pull and
git pull upstream master before you
start to do any work. These steps will be particularly important when
or if you start working in pairs.
git add revisited and
So far, we’ve created a single commit with a single file that we had
already supplied in the
lab0 directory. If you create new files,
Git will not consider them a part of the repository. You need to
add them to your repository explicitly. For example, let’s create
a copy of
$ cp hello_world.py hello_universe.py
hello_universe.py part of your repository? You can
use the following command to ask Git for a summary of the files it
$ git status
This command should output something like this:
On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: test.txt Untracked files: (use "git add <file>..." to include in what will be committed) hello_universe.py no changes added to commit (use "git add" to track).
The exact output may vary slightly (in particular, if you created more files
in Lab #0, they will show up under
Untracked files). However, the important thing is
that there are two types of files listed here:
Changes not staged for commit: This is a list of files that Git knows about and have been modified since your last commit, but which have not been added (with
Untracked files: This is a list of files that Git has found in the same directory as your repository, but which Git isn’t tracking.
You may see some automatically generated files in your
Untracked filessection. Files that start with a pound sign (#) or end with a tilde (~) should not be added to your repository. Files that end with a tilde are backup files created by some editors that are intended to help you restore your files if your computer crashes. In general, files that are automatically generated should not be committed to your repository. Other people should be able to generate their own versions, if necessary.
To add a previously untracked file to your repository, you can just
git add (IMPORTANT: unlike the previous commands, don’t actually run this
just yet; you will be doing a similar exercise later on):
$ git add hello_universe.py
If you re-ran
git status you would see something like this:
On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: hello_universe.py Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: test.txt
Notice how there is now a new category of files:
Changes to be committed.
hello_universe.py not only added the file to your repository,
it also staged it into the next commit (which, remember, won’t happen until
you actually run
git status command reports the status on the local copy of the
full repository. If you wish to look at the status of a smaller part
of the repository (the directory you are working in for example), you
can add a path name to the status command. For example:
$ git status .
reports the status of the current directory (a single dot is the path used to refer to the current directory).
Unstaging, discarding changes, and removing files¶
Take a closer look at the
git status output above. Git is providing you hints in case you want to undo some of your work.
For example, you can use
git reset hello_universe.py to unstage the file. Doing so reverses
git add hello_universe.py so you can create a commit only of changes to other files. This is good practice if you think the changes you made to
hello_universe.py don’t logically go in the commit you are about to make.
Another useful git command is
git checkout. This command will undo
modifications to files. If you again look at the above
output, you will see in the last line that
test.txt was modified. To
undo any changes to the file, type
git checkout test.txt. This
command will revert the file content to match the last commit you made
in your repository’s history.
Finally, if you would like to remove a file from your repository, using
git rm test.txt combines the result of doing
rm test.txt and
git add test.txt.
Looking at the commits log¶
Once you have made multiple commits, you can see these commits, their
dates, commit messages, author, and an SHA-1 hash (a value used by git
to uniquely identify the commit) by typing
git log. This command
will open a scrollable interface (using the up/down arrow keys) that
you can get out of by hitting
You have already changed the
test.txtfile in your
lab0directory. Verify this by using the command
git status. You should see it under
Changes not staged for commit.
git committo create a commit that includes only the
test.txtfile. A good commit message would be “Added my name as Author in test.txt”.
Upload your work to the server using
Verify that this file was sent by again using the command
git status. You should see that the file
test.txtis no longer listed.
If you have not already done so, use
cpto make a copy of
If you run
hello_universe.pyshould show up under
Untracked files. Add it to the repository using
git statusagain. Is
hello_universe.pyin a different category of files now?
Although we have added this file, we have not yet created a commit. Create a commit and push it to the server.
git statusa final time to verify that
hello_universe.pywas committed (if so, you should not see it in any category of files)
git pushto upload your changes to the server.
We strongly recommend you to add, commit and push changed files as often as possible, especially if you finished some work and are about to log off a computer. (We often refer to the process of adding/committing/pushing as *checking-in* your code or *syncing* your repository.) This way the latest files are accessible from any other computer where your repository is set up.
You will be using a locally-developed system named
submit your programming assignments. (You’ll upload files directly to
Gradescope for the short exercises and timed assessments.) The
set-up script that you ran earlier set you up to use
addition to initializing your Git repository.
All chisubmit commands should be run from within your
chisubmit has commands for managing assignments. Here are
descriptions and sample runs of some of the more useful commands.
You can run these commands as you read through this section.
chisubmit student assignment list: lists upcoming programming assignments and their deadlines.
$ chisubmit student assignment list pa0 2020-10-09 23:59:00-05:00 Programming Assignment #0
“Programming Assignment #0” is a mock programming assignment that we have created just so you can familiarize yourself with chisubmit. It will not be graded.
chisubmit student assignment show-deadline <assignment name>: lists deadline information for the specified programming assignment.
$ chisubmit student assignment show-deadline pa0 Programming Assignment #0 Now: 2020-09-26 13:33:23-05:00 Deadline: 2020-10-09 23:59:00-05:00 The deadline has not yet passed You have 13 days, 10 hours, 25 minutes, 37 seconds left
chisubmit student assignment register <assignment name>: registers a student for a specific assignment. You will do this step once per assignment.
$ chisubmit student assignment register pa0 Your registration for pa0 (Programming Assignment 0) is complete.
chisubmit student assignment submit pa0: submits your current commit
$ chisubmit student assignment submit pa0 SUBMISSION FOR ASSIGNMENT pa0 (Programming Assignment 0) -------------------------------------------------------- This is an INDIVIDUAL submission for Gustav Martin Larsson The latest commit in your repository is the following: Commit: eeed8efa66a13c0b04c587acdda43fbe75c9b99b Date: 2020-09-25 14:48:16-05:00 Message: Added log for testing purposes Author: Gustav Martin Larsson <firstname.lastname@example.org> PLEASE VERIFY THIS IS THE EXACT COMMIT YOU WANT TO SUBMIT You currently have 2 extensions You are going to use 0 extensions on this submission. You will have 2 extensions left after this submission. Are you sure you want to continue? (y/n): y Your submission has been completed.
chisubmit has many other commands, including commands for
canceling registrations, canceling submissions etc. You can find
detailed instructions on these and other commands here.
pa0and add your name to the
test.txtfile in the
pa0directory (if you don’t see a
pa0directory in your repository, run
git pull upstream masterto fetch it).
Sync your code with the git server using add, commit, and push.
Submit your “solution” for
VERY IMPORTANT If you work on this lab after October 9th,
do not make a submission for PA #0 with
This will require using your extensions, which are intended
for the real programming assignment (we will revert any extensions
you mistakenly use on PA #0, but this is a cumbersome manual process,
and we prefer that you simply not make any submissions for PA #0
that involve consuming an extension).
git status to check that you have left the local copy of
repository on the CS file server in a clean state. In particular,
make sure you have added (or removed) any extra files that you might
have created. (As always, be careful when you remove a file to make sure
you are in the appropriate directory and are removing the right
files.) And then, if necessary, add/commit/push your files to the
You should always run
git pull and
git pull upstream master
before you start working. When you are done working, you should
always add, commit, and push your code to the git server. Also,
remove any extra files that you might have created along the way. (As
always, when you remove files make sure you are in the appropriate
directory and that you use the correct file names!).
Keeping your local copy of your repository (that is, the one in your home directory on the CS file server) clean and keeping the git server and your home copy of the repository in sync will save you a lot of grief over the course of the term.