Back to Resources

Git in CS 277

by Anonymous, Brad Solomon, Eddie Huang

Overview

Weekly lab assignments and exam coding questions will exclusively use Prairielearn Workspaces (both in notebook form and vscode emulation). However you are required to use git as the version control system for the larger project-based assignments in this class. While we do not require that you learn and use good version control practices, we cannot stress enough how useful a good version control system can be when good practices are used. The following is a brief list of good version control practices:

Again, the above practices are not hard and fast, nor complete, but they should help you complete your coding projects should you use git for them as well.

Course Setup (necessary only once for the entire semester)

The first time you’re accessing the CS 277 repository this semester, you will need to have a CS 277 repository set up for you. This process is simple:

  1. Visit https://edu.cs.illinois.edu/create-gh-repo/sp23_cs277.

This will setup a private github for you that you can use for this course. It will be viewable by the course staff but not by other students. This will allow them to help you while not sharing your private code with anyone else.

Create a clone of your repository

To setup your computer, you will need to clone your repository onto your comptuer.

The URL of your repository will be based on your NetID and you will need to replace NETID with your NetID.

To clone your repository, run git clone using terminal or command prompt:

TIP: If you are using Visual Studio Code, you can also type this into your terminal there! It will make a folder inside whatever location you are actively coding in. You can then move it manually wherever you want.

git clone https://github.com/illinois-cs-coursework/sp23_cs277_NETID cs277git

…you can replace cs277git with whatever folder you want created. For example, you may want to call your folder just “cs277” or anything else.

Finally, move into the directory you just cloned:

cd cs277git

[Optional] Store your git credentials once and for all

Run the following command so that you only have to type in your git credentials once.

git config credential.helper store

Saving Assignment Progress (do this often!)

The main advantage of using git is the capacity to record your progress, ‘roll back’ your history if you encounter a problem, and get quick assistance from course staff when you have a clear problem in your code. To help facilitate this, you should add, commit, and push your work to your git repository frequently. This can always be done using the following commands on a command line while within your CS 277 directory:

git add FILENAME
git commit -m "REPLACE THIS WITH YOUR COMMIT MESSAGE"
git push origin master

You should substitute "REPLACE THIS WITH YOUR COMMIT MESSAGE" with a short message describing what you did since the commit. This will help both you and course staff understand what you did in a specific commit.

Some examples of “good” commit messages:

Some examples of bad commit messages:

Other Useful Commands

# Update your local repository with the remote repository
git pull

# Prints useful information about the present state of your
# local repository relative to the remote repository's state.
git status          

# Prints the commit history of the local repository
git log             

# When you want to redo the making of a new commit (all new edits are kept)
git reset           

# Permanently erases all un-committed changes
git reset --hard

# Permanently undo the latest commit
git reset --hard HEAD^

# Revert the changes specified by the fourth last commit in HEAD and create a new commit with the reverted changes.
git revert HEAD~3