Using Git and GitHub

Setting Up GitHub

We will be using GitHub to distribute the starter files for your labs, and for you to submit your work. GitHub is a widely used platform to store code that uses the Git protocol to save all changes to your code. The great thing about using Git is that it allows you to go back to earlier saved versions of your code if you make a mistake.

ReadMe

You should save your files back to git whenever you make progress on part of the lab assignment, and especially before you leave the lab.

The first thing you will need to do is create a GitHub account. Go to github.com and create a new account using the signup link in the upper right hand corner of the website. You can choose any username that you like. If you already have a GitHub account, you can continue using that account. Almost every programmer has a GitHub account, and it’s a great place to save code that you might want to share with people (like potential employers).

Now that you have a GitHub account, click the link on the first page of the lab to create the repository for Lab 1. A git repository is just a collection of code saved using the git program: we will be creating one repository per lab assignment. When you click the link, it will ask you to login to your GitHub account, and then connect it to your actual name - this is so we can grade your assignments when you submit them, and connect that grade to you! If you registered late for this class, your name may not be on the list - please talk to the lab instructor if that happens.

Once you have clicked the link, it will take a couple of seconds to create a new repository with the files you need for the lab. This repository will be titled lab1-xxx, where xxx is your GitHub username. You can see this repository and all the files in it if you click on the icon in the upper right hand corner of GitHub, and then select “your repositories.” Click on the name of the repository. You should see a list of files with a short description (called a “commit message”, because you write it when you save, or commit, a file to GitHub), and the time when they were committed, which should be approximately now, since the repository was just created.

Using the Terminal and cloning your repository

We will be using the Linux Terminal to interact with git, and to run your code. The Terminal is a powerful tool that lets you interact with the operating system in a text based way. To start, open the Terminal by clicking on the “nine dots” icon in the bottom left of your screen, typing “Terminal” in the search box that appears at the top, then click on the “Terminal” program, as shown in this screenshot:

Now, we’re going to use git to check out the repository you just created. The first step is an authentication step, so that GitHub knows that you want to be able to check out repositories on this computer. You should only have to do this step once.

In the Terminal window, type:

gh auth login

In the dialog options that appear:

  • Choose “GitHub.com” as the account you want to log into
  • Choose “SSH” for your preferred protocol
  • Press Enter to choose the default public key
  • Press Enter to use the default title for your public key
  • Choose “Login with a web browser” as your authentication process
  • Type the Enter key to continue

This will open a browser window. You should use the browser to log in to GitHub and enter the 8-digit code that gh tells you to enter.

Now that you’re authenticated, you’ll clone your lab 1 repository. This will copy the files from your repository to your computer, and allow you to copy your changes back to GitHub (which is how you’ll submit your lab to us). In your browser where you have GitHub loaded, navigate to your repository. There should be a big green button that says “Code” in the upper right corner. Click on the arrow on that button, and then go to Local and SSH. There should be some text that says something like “git@github.com:CSCI151F24/lab1-xxx”. In the Terminal, type

git clone git@github.com:CSCI151F24/lab1-xxx

replacing “git@github.com:CSCI151F24/lab1-xxx” with the text from GitHub.

This should have created a folder on your computer with the same name as your repository, and all the files you need for the lab in it.