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 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.
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 button that says "<> Code".
- You'll see a URL; copy that URL (easiest by clicking the button that looks like two stacked squares).
- Open VS Code.
- Make sure you are logged into the CS 70 server
- 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).
- Click "Clone Repository".
- In the textbox at the top of the window, paste the URL you copied.
- Now edit the path to choose a location. We recommend 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. 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
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
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.
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.)