owned this note
owned this note
Published
Linked with GitHub
---
tags: resources
---
# CS200 GitHub Guide
We use GitHub and git to give you access to project code, to allow you to save your work online so you can access it from anywhere, and to facilitate collaboration on partnered work. In CS200, we will be expecting you to access git through the terminal/command line and through GitHub. GitHub does have a companion app, but we do not recommend you use it and will not be able to support you in making it function.
## What is GitHub?
GitHub is a code-hosting platform that is used by many programmers to save their code and access it from any machine. Think of it like “the cloud” but for code projects! This guide is your go-to resource for help with GitHub/git setup as well as git commands you should know in order to interact with GitHub from your local machine.
## Making an Account
First, you're going to need a GitHub account which will be an invaluable resource to you for the rest of your computer science career (both at Brown and beyond). To create an account:
1. Go to www.github.com
2. Select "Sign up" in the upper right corner
3. Follow the steps on the website to get your account all set up :)
## Installing Git
Thankfully, installing git on your computer is super easy! First, check if you already have git installed on your computer. To do this, type `git --version` in your terminal. If you already have git installed, your terminal should print the version you have (the version you have shouldn't matter, as long as you have it installed). You can ignore the rest of this section.
If you don't already have it installed, follow the instructions below:
### On a Mac
- Download an installer at [this link](https://sourceforge.net/projects/git-osx-installer/files/), the version doesn't matter
- Follow the prompts to install Git
- Verify you have Git installed by typing `git --version` in your terminal
### On a Windows
- Go to [this page](https://git-scm.com/downloads), and click “Windows.” This should prompt an automatic download of git, but if not, click the link to manually download git.
- Open the .exe file that was downloaded and click next through each of the installation pages (the default settings are perfect for us!).
- Verify you have Git installed by typing `git --version` in command prompt.
## Configuring Git Settings
Now you have to connect git on your computer to your GitHub account.
- First type into your terminal / command prompt window: `git config --global user.email “<email>”` where \<email\> is replaced with the email you used to make your GitHub account (don't forget the quotes!).
Then type:
- git config `--global user.name “<name>”` where \<name\> is replaced with your username (don't forget the quotes!).
Nothing should print in the terminal after you hit enter when you do these steps, but they are important for when you are trying to update your GitHub code later!
## Authentication to GitHub
When you connect to a GitHub repository from Git, you’ll need to provide credentials to prove that you are who you declare to be. To do this, you can create a Personal Access Token.
**Note:** If you had a GitHub account before, you may have used a password-based authentication. This is no longer supported, so you also need to follow the steps below!
- Use this [guide](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) to create your Personal Access Token.
- On step 7, when giving your token an expiration date, choose the ‘No expiration date’ option. (Ignore the GitHub warning). If you choose any of the other options, you will have to create a new token when this one expires.
- On step 8, when defining the scope of the token, you can select as many scopes as you wish but make sure to select repo
- Once created, copy the token and save it somewhere you can easily access e.g., notes or email
Every time you try to clone / push to GitHub it will ask for your password, but what it's actually looking for is your access token. This gets really annoying. We'd recommend configuring your computer to do this automatically.
**Important:** save yourself a lot of future pain by typing the following into your terminal / command prompt:
- `git config --global user.password "<access token>"` where \<access token\> is replaced by the access token you just created!
The first time you clone an assignment after following these steps you may be prompted for your GitHub username and password (this will be your personal access token). Please enter these and you should be all set!
## Git Terminology
Before we jump into the important git commands we will be using, here is some important GitHub terminology you should familiarize yourself with:<br>
- **Repository** → a GitHub repository – or repo for short – is what a project on GitHub is called. Each time you accept an assignment for CS0200 by clicking on the assignment link, GitHub will create a repository for you for that project.<br>
- **Commit** → The cool thing about GitHub is that it can keep track of all of the versions of your project as you edit them. Each project “version” is called a commit. It is basically a snapshot of your project at a moment in time, and it is up to you to create commits when you reach points in your project that you do not want to lose. (Your project will be saved on your local machine, but in order to save a snapshot on your GitHub, you must create a commit and push it to your GitHub). It is good practice to create commits regularly so if something gets messed up while you are coding, you will have old versions to look back at stored on your GitHub repository.
The git commands below might prove useful when trying to get your code from GitHub to your computer or when you are trying to commit your code.
## Need To Know Commands
| Command | Explanation |
|------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `git clone <repo URL>` | Once you accept an assignment and your repo is created, click the green “Code” button and copy the link that is listed. That link is your repo URL. Then, in your terminal, type this command with the repo URL to make a folder with the code in your repo on your computer. The folder will be made in whichever directory you are currently in, so be sure to `cd` into your desired directory before running this command! |
| `git add <file>`<br> <br>`git add -A` | This command is the first of 3 commands that you need to run when you are trying to get the code you wrote on your computer back up to GitHub. You must add the files that you want to update on GitHub. You can do this by running `git add` with one file specified at a time, or you can use `git add -A` to update all files (typically what is used when you want to save a snapshot of your current code). |
| `git commit -m “message”` | Once you have added all of the desired files using `git add`, you are ready to commit these changes and save your snapshot to GitHub! This command is the 2nd of 3 commands you must run to get your code edits back up to GitHub. It creates the commit, or “snapshot” that we will soon send to GitHub. Instead of `<message>`, you should write something informative about what you've changed! |
| `git push` | Now you’re ready to push the changes to GitHub! Running this command will send your commit to the online repository where your code is stored. This is the final of the 3 commands you will run to get your code back to GitHub! After running this, go on your GitHub repo and ensure that your updates were made! |
| `git pull` | This command lets you pull any changes on this repository that are present on GitHub but not on your local machine. No need to worry about this for solo projects, but if you’re working on partner projects, pull before you begin working / after you commit and before you push in order to get all your partner’s changes! |
If you have any git problems, feel free to post on Ed!
## Accepting an Assignment on GitHub Classroom
Accepting assignments through GitHub Classroom can be a confusing process – do not fear, this section is here to help! Follow these steps and accepting assignments should be a breeze (but if it's not, please come to TA hours and we'll be more than happy to help you troubleshoot).
:::info
**Aside: Before the First Assignment**
*For CS17/19/111 students this step should be done before HW1A, for CS15 students this step should be done before HW2*
Create a CS200 folder on your computer. This folder will hold all of your assignments for the rest of the semester. We recommend putting it on your Desktop (Mac) or the C Drive (Windows) for ease of access, but you can put it wherever makes sense for you!
:::
**Follow these steps for **every**(!) assignment you accept through GitHub Classroom this semester.**
1. Accept the assignment on GitHub Classroom by following the link on the handout and clicking the “Accept this assignment” green button
2. After a few seconds, refresh the GitHub page, you should see a link labeled "Access your Assignment" – click this link
3. Click the green “Code” button, which will open a dropdown that says “Clone”, then copy the link that is shown.
<center>
<img src="https://i.imgur.com/8834CLx.png" width="40%">
</center>
4. Open up the terminal (Mac) or command prompt (Windows) of your computer
5. Use the `cd` command to enter into the CS200 folder of your computer. (take a look at our [Terminal Guide](https://hackmd.io/Q5-3cN82TYqV4NaztvhxnA) for more info on what `cd` and other shell commands do) <br>
*If your CS200 folder is on your Desktop/C Drive, you can `cd` there as shown below:*
<br> `cd ~/Desktop/CS200` or `cd /Users/<yourName>/Desktop/CS200`(Mac)
<br> `cd C:\CS200` (Windows)
6. Now you’ll have to paste the link from before in order to clone the repository locally. You should type `git clone <pasted link>` (without the “<>” brackets)
Yay! You now have cloned the assignment onto your machine! To run it in IntelliJ you can go to File > Open > and navigate to your assignment folder (click the folder with the name `<assignment>-<github login>`)!
______________________________
*Please let us know if you find any mistakes, inconsistencies, or confusing language in this or any other CSCI0200 document by filling out the [anonymous feedback form](https://docs.google.com/forms/d/e/1FAIpQLSdFzM6mpDD_1tj-vS0SMYAohPAtBZ-oZZH0-TbMKv-_Bw5HeA/viewform?usp=sf_link).*