Getting Down to Work
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 Visual Studio Code Setup
Once you have accepted an assignment from GitHub Classroom, it will appear as a repository on GitHub.
The next step is to get a copy of that repository on the server so you can work on it. We'll generally call this copy the “local” or “working” copy.
Hay, wait! It's not local! It's on the remote server!
Yes, the terminology is confusing. “Local” here is in contrast to the “remote” copy which is stored on the GitHub servers.
So the copy of the repository you will work on is local to the CS 70 server.
(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.
- Go to your repository on GitHub.
- Click the green button that says .
- You'll see a URL; copy that URL (the easiest way is to click the button that looks like two stacked squares).
- Open VS Code.
- Click on the
for the host (whereusername @cs70.cs.hmc.eduusername is replaced with your CS 70 server username). When prompted, enter your server password.
button in the lower-left corner. In the pop-up menu, select and enter - On the sidebar of your VS Code window, click the “Explorer” icon (looks like two overlapping pieces of paper) or the “Source Control” icon (looks like three circles connected by two lines).
- Click .
- In the text box at the top of the window, paste the URL you copied from GitHub.
- Now edit the path to choose a place to save the cloned repo. We recommend using the
cs70
directory that is already in your home directory. - VS Code will download the repository and ask if you want to open the repository. Say yes!
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
to push the new version of the file to GitHub.Getting Changes from GitHub
Imagine that you and your partner have been working on your project using your server account. Then, in your next work session, your partner is the one who logs into the server. Their project files are out of date, so they'll need to check for any changes that you 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
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, but ensuring your copy of the repo is up to date before you start to work is a good habit.
For more details about Git, along with a glossary of Git and GitHub terminology, see the GitHub Help page
(When logged in, completion status appears here.)