CS 70

Getting Down to Work

  • LHS Cow speaking

    Now that you have your various remote accounts set up and working, it's time to see how to actually work on assignments!

Local Repository and VS Code Setup

Once you have checked out an assignment from GitHub Classroom, it will appear as a repository on GitHub.

The next step is to get a copy of the repository on the server so you can work on it. We'll generally call this the "local" copy.

  • Horse speaking

    Hay, wait! It's not local! It's on the remote server!

  • LHS Cow speaking

    Yes, the terminology is confusing. "Local" here is in contrast to the "remote" copy which is stored on the GitHub servers.

  • RHS Cow speaking

    So the copy of the repository you will work on is local to the CS 70 server.

  • LHS Cow speaking

    (Which is, admittedly, "remote" from the perspective of your computer.)

Cloning and Opening the Repository in VS Code

Getting a copy of a Git repository that you can work on is called cloning. You could do everything you'll need to using the git command-line tool (or any of a number of GUI Git clients), but Visual Studio Code has support for working with Git repos built in.

  1. Go to your repository on GitHub.
  2. Click the button that says "<> Code".
  3. You'll see a URL; copy that URL (easiest by clicking the button that looks like two stacked squares).
  4. Open VS Code.
  5. Make sure you are logged into the CS 70 server
  6. On the sidebar of VS Code click the "Explorer" icon (looks like two pieces of paper) or the "Source Control" icon (looks like three circles connected by two lines).
  7. Click "Clone Repository".
  8. In the textbox at the top of the window, paste the URL you copied.
  9. Now edit the path to choose a location. We recommend the cs70 directory that is already in your home directory.
  10. VS Code will download the repository and ask if you want to open the repository. Yes, let's.

Editing Files and Committing Changes

Open the file written-answers.md and edit it to add a new line at the end of the file:

I followed the instructions in Episode 2!

Now you have a change in your local copy of the file written-answers.md. To tell git that you have a change it should pay attention to, you will need to stage the changed file (put it on the list of files that git should include in the next commit) and then commit the staged changes to your local repository. The Source Control window in VS Code allows you to stage your changes by using the + button next to the file name. You can then add a brief comment describing the change you're committing, and then commit your changes using the (check mark) button.

Below is a video showing you the process. (Don't worry that the shell in this video doesn't look the same as yours).

Sending Changes Back to GitHub

You can continue making changes, staging them, and committing them to your local repository, but those changes are only in your local repository unless you copy them to a remote repository—in this case, your GitHub repository for the assignment—by pushing your local changes to the repo on GitHub.

In the Source Control window in VS Code, click … ⇒ Push/Pull ⇒ Push to push the new version of the file to GitHub.

Getting Changes from GitHub

Say, in a future week, you and your partner have been working on your project using your server account. Then, in your next work session, it's your partner that logs into the server. Their project files are out of date! You'll need to check for any changes you may have made and pushed to your shared GitHub repo.

Getting changes from your remote repo requires you to pull changes from the remote repo into your local repo. In VS Code, you can use the … ⇒︎ Push/Pull ⇒︎ Pull command in the Source Control window.

Best practice is to always pull changes from upstream before you start working on changes of your own. Because you and your partner are pair programming, of course, you should both know what's changed.

  • RHS Cow speaking

    For more details about git, along with a glossary of git and GitHub terminology, see the GitHub Help page

To Complete This Part of the Assignment…

You'll know you're done with this part of the assignment when you've done all of the following:

(When logged in, completion status appears here.)