Git and GitHub

MATH/COSC 3570 Introduction to Data Science

Dr. Cheng-Han Yu
Department of Mathematical and Statistical Sciences
Marquette University

Version Control and Collaboration
Git and GitHub

Git and GitHub

  • Git is a version control system – like Track Changes features from MS Word, on steroids.
  • It’s not the only version control system, but it’s a popular one.

  • GitHub is a home for Git-based projects (repository, or repo) on the cloud – like Dropbox but much better.
  • We’ll use GitHub for web hosting homework.

Versioning

Source: Data Science in a Box Unit 1 - Deck 3

When we want to take a snapshot of our current work, we create a commit.

Versioning with human readable messages

  • Informative messages: let the next person know what happened with each change.

Source: Data Science in a Box Unit 1 - Deck 3

Why Need Version Control

When you commit a file or set of files,
Git will save some information automatically.

How We Use Git and GitHub

Source: Data Science in a Box Unit 1 - Deck 3

How We Use Git and GitHub

  • You clone the repo I create for you to your Posit Cloud as an project.

Source: Data Science in a Box Unit 1 - Deck 3

How We Use Git and GitHub

  • You push your updated work in Posit Cloud back to GitHub.

Source: Data Science in a Box Unit 1 - Deck 3

Git Ready for Data Science

  • Go to https://github.com/ to create a GitHub account if you don’t have one.
    • Use the same username and email address of your Posit Cloud.
  • Account (topright) > Settings
    • Emails > Uncheck “Keep my email address private” (Link your R/Python work to GitHub)
    • Public Profile > Cool name and nice picture!
  • Share your GitHub username at https://forms.office.com/r/k0L5M5TyS7, so I can invite you to join our course organization math3570-s24.

Git Ready for Data Science

  • Please accept my invitation to join the GitHub organization math3570-s24.

Git and GitHub Tips

  • Posit Cloud has installed Git for us! 😄
  • There are millions of git commands, and very few people know them all.
  • 99% of the time you will use Git to add, commit, push, and pull.
  • If you google for help and this is the solution…
  • Skip that and move on to the next resource!

Connecting Posit Cloud and GitHub Together

Connect Posit Cloud and GitHub: Step 1

  • Posit Cloud cannot recognize your GitHub account unless you connect them each other.

  • In Posit Cloud, click on your name on the top-right corner to open the right menu.

  • Click on Authentication.

Connect Posit Cloud and GitHub: Step 2

  • In the Authentication window, check the box for Enabled.

Connect Posit Cloud and GitHub: Step 3

  • For your GitHub page, click on the green box that says “Authorize rstudio”.

Connect Posit Cloud and GitHub: Step 4

  • Back to the Authentication of Posit Cloud, check Private repo access also enabled.

  • Make sure math3570-s24 shows up under Organization access.

  • Click on Request

  • Click on the green box “Authorize rstudio”.

Connect Posit Cloud and GitHub: Step 5

  • Once you’re done, both of these boxes should be checked.

Connect Posit Cloud and GitHub: Step 5-1

Connect Posit Cloud and GitHub: Step 6

  • Confirm that you’ve linked up your GitHub and Posit Cloud accounts GitHub settings > Applications. Should see Posit Cloud listed as an authorized app under Authorized OAuth Apps.

GitHub to Posit Cloud

GitHub to Posit Cloud: Step 1

  • Each of your assignments will begin with the following steps.
  • Go to the repo named hw00-yourusername I created for you.

GitHub to Posit Cloud: Step 2

  • On GitHub,
    • Click on the green Code button, select HTTPS.
    • Click on the clipboard icon on the right to copy the repo URL, such as https://github.com/math3570-s24/hw00-chenghanyu.git

GitHub to Posit Cloud: Step 3

  • Go to Posit Cloud and into the course workspace 2024-spring-math-3570.
  • New Project > New Project from Git Repo.

GitHub to Posit Cloud: Step 4

  • Copy and paste the URL of your assignment repo into the dialog box.
  • Hit OK, and you’re good to go!

GitHub to Posit Cloud: Step 5

  • Click hw00-yourusername to do your assignment in Posit Cloud!
  • Done! We learned the entire process of cloning a repo on GitHub to Posit Cloud as a project.

  • Next, we’ll see how to keep your revision record (commit) and send (push) the latest revised version of your work from Posit Cloud to GitHub!

Posit Cloud to GitHub

Personal Access Token (PAT): Step 1

  • GitHub has removed the support for Password Authentication for Git operations.

  • Before we can send our work in Posit Cloud to GitHub, we need Personal Access Token (PAT)

  • Settings > Developer settings

Personal Access Token (PAT): Step 2

Personal Access Token (PAT): Step 3

Personal Access Token (PAT): Step 4

Personal Access Token (PAT): Step 5

  • Copy and paste your PAT to a secrete and safe space!!

Posit Cloud to GitHub: Step 1 - Edit your file

  • Open a Quarto (qmd) file in your project, in YAML change the author name to your name.

  • Click Render to generate your beautiful document. (If you are asked to install any packages, please do!)

Posit Cloud to GitHub: Step 2 - Commit changes

  • Go to the Git tab in your RStudio.
  • Click on Diff. This shows you the difference between the last committed state of the document and its current state that includes your changes.
  • Check Staged box to add files to be committed.
  • Write “Update author’s name” in the Commit message box and hit Commit.

Posit Cloud to GitHub: Step 3 - Push changes

  • We’ve made an update and committed this change locally.
  • It’s time to push the changes to your repo on GitHub, so that others (Dr. Yu) can see your changes.
  • Click on Push.
  • In the prompted dialogue box, enter your GitHub user name, and your password (PAT).

Posit Cloud to GitHub: Step 3 - Updated Repo

  • Back to your GitHub repo and refresh it.

  • The online repo is now synced with your local project in Posit Cloud.

Resources