← All activities
Week 8 · Activity

Activity: Code It (Commit, Pull & Push on GitHub)

Set up a personal access token and run your first pull / commit / push cycle from Posit Cloud. Estimated time: 10 minutes.

📋 What to do

  1. Prerequisites: a GitHub account; a repository you created or were added to; and the full URL of that repository (it should end in .git). Complete the "Create a GitHub Repository" activity first if you have not.
  2. On GitHub.com, click your profile icon in the upper right, then Profile, then Developer Settings in the left-hand menu.
  3. Create a Personal Access Token. You can make a fine-grained token, scoped to one repository, or a classic token, which grants the bearer access to all of your repositories.
  4. If classic: name the token; give it an expiration date after the end of the term; and under Scopes select public_repo and repo.
  5. If fine-grained: name the token; give it an expiration date after the end of the term; and under Permissions select Contents (which adds Metadata automatically). Make sure Contents is set to Read and Write.
  6. Copy the token and store it somewhere safe — a password manager, or a private note. Treat it like a password: anyone holding it can act as you on GitHub. You will not be able to view it again after you leave the page.
  7. Open Posit Cloud and create a new project from GitHub, using your repository's .git URL.
  8. Install the two packages you need: install.packages(c("gert", "credentials")).
  9. Create one new file in the project, so there is something to commit.
  10. Run the script below, then copy the output of your R Console and terminal into the Canvas text submission box. It should contain the word git a lot.
library(gert)
library(credentials)

credentials::set_github_pat()
# prompts a popup asking you to enter your GitHub Personal Access Token

gert::git_pull()                          # pull the most recent changes from GitHub
gert::git_add(dir(all.files = TRUE))      # stage every new or edited file
gert::git_commit_all("my first commit")   # save your record of the edits (a commit)
gert::git_push()                          # push your commit up to GitHub

📮 Submit

Submit on Canvas (1 pt) — graded on completion; your deadline is on the Canvas assignment.

Note: keep this page as your copy of the activity after class — it is the version we maintain, links to surveys and slide decks included. Submission, the due date, and your grade are on Canvas.