SD 212 Spring 2023 / Homeworks


This is the archived website of SD 212 from the Spring 2023 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

hw33: Create, clone, and push to GitHub

  • Due before the beginning of class on Monday, May 1

Overview

This homework assignment asks you to interact with git repositores that are hosted on GitHub. It is based around our current unit and will give you practice creating, cloning, pulling, adding, committing, and pushing – basically all of the important things you need to do with git!

You have extra time to complete this HW but take note of intermediate deadlines and know that it will be impossible to do this at the last minute. There is actually not that much “work” in this HW, but there are multiple steps that require interacting in some cases with others, so you need to complete at least the first part early.

Part 1 (due Friday morning): Make a GitHub account and fill in spreadsheet

  1. Make an account for yourself on github, if you don’t have one already.

  2. Once your account is activated, add your GitHub username at the right spot on this Google sheet.

Note that GitHub is the de facto standard place to share and collaborate on coding projects. Many people seeking employment as data scientists share their GitHub profile to show off their work. So try to make a sensible username and consider using your personal email address so that you can keep access to this account after graduating.

Part 2: Create a shared repo for Lab 7

We started lab 7 this week. Most of you are working with a partner.

For this part of the HW, you need to create a new git repository for your lab 7 code, push it to a new private GitHub repository, and invite your teammate (if you have one) as well as your instructor to join the repo.

Here are the steps you need to follow to get this done, specifying which lab partner does each part.

  1. Configure git (everyone)

    • Open a terminal wherever you want to work on lab 7

    • Run these commands, replacing with your actual name and actual email address:

      git config --global user.name "YOUR NAME"
      git config --global user.email "YOUR@EMA.IL"
      git config --global init.defaultBranch main
    • Create an ED25519 SSH key. Run

      ssh-keygen -t ed25519

      Hit enter to accept the default file location.

      If it says the file already exists, then you’re good; do not overwrite it.

      Otherwise, when prompted for a passphrase, just hit Enter (leave it empty with no passphrase).

    • Display your SSH key on the terminal and copy it to the clipboard. Run:

      cat ~/.ssh/id_ed25519.pub

      which should display a single long line encoding your public key. Copy that entire line to your clipboard.

    • Login to github in a web browser

    • Add the new SSH key to GitHub: Click your login circle at the top right, go to “Settings”, then “SSH keys” on the left-hand menu, and then click “New SSH key”.

      Paste your ed25519 public key from the terminal into the “Key” box and click “Add SSH key”.

    • Test it worked: Go back to the terminal and run

      ssh git@github.com

      You should see a message like this:

      Hi <YOUR_GITHUB_USERNAME>! You've successfully authenticated, but GitHub does not provide shell access.
      Connection to github.com closed.

      This is not an error! It’s just a check to make sure that your SSH key is set up correctly. If you see your own GitHub username there, then it means you’re all set.

  2. Create local git repo (Lab partner 1, or if working solo)

    • Open a terminal wherever your lab 7 directory is

    • In the lab 7 directory, type git init to create a new repo

    • Important: If you are running on a lab machine or csmidn, your version of git is old and busted. That’s OK, but you have to run this extra command right after you run git init in order to bring things into the 2020s:

      git symbolic-ref HEAD refs/heads/main
    • (Optional, but recommended): Tell git to ignore the large csv file and python cache directory to save time when pushing and pulling, by creating a new file called .gitignore (with the leading .) containing these two lines:

      submit-data.json
      __pycache__/
    • Add all other files to your new git by running git add .

    • Commit these initial files by running

      git commit -m "initial commit"

      (You can change the message “initial commit” to whatever you want.)

  3. Create GitHub repo (Lab partner 2, or if working solo)

    • Login to github

    • Create a new repository (+ sign at top-right of window)

      • Name it something like “sd212lab7”
      • Set it to private not public
      • Leave everything else blank (no README, no gitignore, no license)
    • Invite your lab partner as a collaborator (if applicable)

      • Go to your new repo on GitHub and click the box to “Invite collaborators”.
      • Click the “Add people” button
      • Enter the GitHub username of your lab partner (check the spreadsheet if needed)
  4. Push local repo to GitHub (Lab partner 1, or if working solo)

    • (If applicable) Accept your lab partner’s invitation to their lab 7 repo on github.

    • Go to the webpage for the lab 7 repo on github. Find the SSH line for this repo and copy it to your clibpoard — it should be something like git@github.com:USERNAME/lab07.git

    • Open a terminal in your lab 7 directory

    • Run git status. It should say “nothing to commit, working tree clean” because you already did the commit during step 2 above.

      (But your local repo is still not connected to github, so we need to do that next!)

    • Add the GitHub repo as a new “remote” by running

      git remote add origin git@github.com:USERNAME/lab07.git

      where the last part is pasted from your clipboard.

    • Push to this new remote to GitHub

      git push -u origin main
    • If you go back to the GitHub page and refresh it, you should see the files you just pushed. Aweseome!

  5. Clone GitHub repo from lab partner (Lab partner 2; skip if working solo)

    • Open your repo’s page in github

    • You should see the files your partner pushed. Click the green “Code” button and copy the SSH link that starts with git@github.com

    • Open a terminal and clone the repository by running

      git clone git@github.com:USERNAME/lab07.git

      where the last part is what you pasted from the clibpboard

  6. Add your instructor as another collaborator (one person must do this, even if working solo)

    • Open your repo’s page in github

    • Go to Settings (top bar), then Collaborators (left side), then “Add People” (green button). Find your instructor’s github username on the shared spreadsheet.

Part 3: Clone the shared class-wide repo and make your mark

After you add your GitHub username (Part 1), your instructor should sometime later send you an invitation to collaborate on the shared public repo at https://github.com/sd212usna/share23.

(Both lab partners do all of this separately.)

  1. Get the SSH link for the shared repo

    • Open the shared repo page on github

    • Click the green Code box, select the SSH option, and copy the line that starts with git@github.com: to your clipboard

  2. Clone the repo to a local directory

    • Open a terminal in your sd212 folder (not inside your other repo for lab 7!)

    • Clone the shared repo by running:

      git clone git@github.com:...

      where the last part is what you pasted from the clipboard

    • Check that this downloaded and created a new folder called share23

  3. Modify a file

    Find the secX.py file corresponding to your section, and follow the instructions there to add some code to YOUR function (only!).

    Save and run that program to see if it’s working. Do not edit other people’s code. (If something is broken in someone else’s code, let them know they should fix it!)

  4. Create a new file

    Add a new file in the folder secXfiles for your section with filename m250000.txt but using your actual alpha of course.

    You can put anything you want in the text file. I recommend some tasteful ASCII art.

  5. Commit the two changes that you just made to the local copy.

    • In the terminal, use cd to go to the folder share23

    • Run git add for your new file, like

      git add secX/mYYYYYY.txt
    • Commit both changes by running

      git commit -a -m "MIDN 3/C Jones reporting in"

      (Note, the -a flag means “all” and will include your changes to the Python file as well as the new file you just added. And of course you can change the message after -m to anything you want.)

  6. “Push” your commit to the shared repo

    • In case some other changes were made in the meantime, run

      git pull

      to update your repo to the most recent version

    • Not push your commit:

      git push origin main

      (It might also work if you leave off the origin and main parts.)

    • Confirm it worked! Go to the shared github page and make sure you see your changes in the Python program as well as the new file you created in the section directory.

That’s everything! Make sure to go back and make sure you understand the commands you ran and what they did. Challenge yourself to go back to the repo again the next day and make some more changes to your python function.