teaching machines

Homework 0 – The Git Sandwich

June 6, 2019 by . Filed under cs1, fall 2019, specifications.

For homework 0, you gained access to your homework repository on GitLab, cloned it on your local machine, and pushed those local changes back up to GitLab. In this installment, you will learn to synchronize in the other direction—you will pull changes down from GitLab to your local repository.


Suppose you’re home for the weekend, and you get the craving to work on a CS 1 homework. Alas, you left your laptop (machine A) in your room. Good news, you can install IntelliJ and clone your remote repository on your home computer (machine B) just as you did on machine A when you completed homework 0. While home, you successfully make your changes on machine B, commit them, and push them back up to GitLab.

Once you get back to campus, however, you realize that those changes exist only on GitLab and machine B, which is back home. You do not have them on machine A, which is in your room. How do you get them? You pull them down.

On machine A, click VCS / Git / Pull. All changes on GitLab will be brought down and integrated into your local repository. GitLab and Git can make working on a project on multiple machines a reasonably pleasant experience, but you need to be careful to follow the Git Sandwich to avoid conflicts or missing files.

The Git Sandwich

Trouble can happen if you try to pull down remote changes to a file that has also been changed locally. Imagine editing a paper as a team. You make changes to your copy of the introduction, and so does a teammate—to her copy. Someone then has to go in and combine your separate changes manually. In Git terminology, this situation is called a conflict.

Since only you are the one making changes to your code in this course, you can avoid conflicts completely by making sure you follow these procedures every time you sit down to work on homework in this course:

  1. Pull down remote commits from GitLab.
  2. Complete more of the homework assignment.
  3. Commit all changes. In particular, be sure to check Unversioned Files in the commit dialog to add any previously uncommitted files: If you do not check these new files, they will not be on GitLab and therefore will not pass the SpecChecker tests.
  4. Push the local commits to GitLab.

The intent is that after every coding session, you get your changes up on GitLab, and before every coding session, you grab any changes from GitLab. If you follow this procedure, there’s no way for changes to appear on both the local and remote sides and cause a conflict.

Do not wait until the homework is completely done before committing and pushing. Surround each of your coding sessions with the Git Sandwich!