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 GitHub 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 local copy of the repository on your machine so you can work on it.

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, which is especially useful when you're also working inside a development environment provided through Docker.

You can clone the files from inside VS Code by using the “Clone Repository” command in the Explorer. Once you have them, you can open them inside your Docker container.

  • RHS Cow speaking

    It is always easiest to begin in a new (empty) window in VS Code!

Video How-To

The following video walks you through the process of cloning a repo in VS Code.

Note that the video recommends that you don't click Open once you've cloned the repository, but you actually have two choices:

  1. Click Open, but when VS Code pops up a message offering to “reopen the folder in a container”, say yes. This dialogue box only appears briefly, so you need to watch for it.

    • If you missed the “reopen in a container message”, close the window and then proceed with the second option.
  2. Alternatively, you can open the local copy of your homework files in VS Code. For CS 70, you should always use the Open Folder in Container command in the Remote Explorer to open your homework files.

    • This option is also a bit error prone, as the Open Folder in Container menu option is not always easy to find; sometimes you need to click a + button, but it may be easiest to just press the F1 key and type Open Folder in Container into the dialog box that appears.

Using VS Code with a Partner

Starting with Homework 1, you will have a homework partner.

  • In the pair-programming lab we have a specific setup to let you easily collaborate—two keyboards, two monitors, one computer. How cool is that?!
  • If you and your partner are working in-person with just one computer, you can just swap seats when it's time to change roles.
  • If you and your partner are working in-person or remotely with two computers, you can approximate the lab setup with a Live Share session in VS Code.

You are welcome to try out Live Share this week, but you won't need to code with a partner until next week.

Here's a video showing how that works:

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 Part 7!

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.

The first time you try to commit on a computer, you may get an error message telling you that git doesn't know who you are. If so, in the terminal inside VS code, use git config to set up your user information:

git config --global user.name "Your Full Name"
git config --global user.email "Your GitHub Email Address"

replacing Your Full Name with your full name, and Your GitHub Email Address with the email address you used to sign up for GitHub. (Make sure you use the double quotation marks (") to enclose your arguments.)

Note: If you're using one of the machines in the pair-programming lab, you'll need to set these options for each session. (The lab machines start with fresh environments after every log out.) On your own machine, you should only need to set that configuration once.

Here's another video showing you the process:

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.

Warning

Because the lab machines wipe everything after you log out, you must push your changes to GitHub or they will be lost.

Getting Changes from GitHub

In future weeks, if you and your partner are working on your own computers, you'll each need to check for any changes your partner may have made and pushed to your shared GitHub repo. (On the lab machines you have to clone the repository every time you start working, so you'll automatically get all the changes that have been made.)

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 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.

  • LHS Cow speaking

    For a detailed tutorial on using Git tools with VS Code, 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.)