Before class

  • Remind students to setup a GitHub account and email the instructor their username.
  • Setup class organization at Github.
  • Add students’ username to organization with “create repo” permissions and respond with link to organization in email.

For class

library(dplyr)

data_size_class <-
  data %>% 
  rowwise() %>% 
  transmute(id = id, earlengthcat = get_size_class(earlength, 10))
  • Open the following links in a browser and zoom in to make the images fill the screen.

Live coding demo parallels assignment.

Introduction

Motivation

Benefits of version control

Version control using Git & RStudio

Create a Git repo

  1. Navigate to Github in a web browser and login.
  2. Click the + at the upper right corner of the page that shows the words Create new... when you hover over it and choose New repository.
  3. Choose the class organization (e.g., dcsemester) as the Owner of the repo.
  4. Fill in a Repository name that follows the form FirstnameLastname.
  5. Select Private.
  6. Select Initialize this repository with a README.
  7. Click Create Repository.

Connect to the Git repo in RStudio

  1. File -> New Project -> New Directory -> Version Control -> Git
  2. Navigate to your new Git repo -> Click the Clone or download button -> Click the Copy to clipboard button.
  3. Paste the Repository URL: A suggested Project directory name: should be automatically generated.
  4. Choose where to Create project as subdirectory of:.
  5. Click Create Project.
  6. Check to make sure you have a Git tab in the upper right window.

Do Exercise 1 - Set-up Git.

First commits

The following example uses the code from the Data Management Review exercise.

Commit data

Commit R script

get_data <- function() {
  data <- read.csv("houseelf-earlength-dna-data.csv")
  return(data)
}

data <- get_data()

Building a history

get_size_class <- function(earlength){
  if (earlength > 10){
    size_class = "large"
  } else {
    size_class = "small"
  }
  return(size_class)
}
get_size_class <- function(earlength, threshold){
  if (earlength > threshold){
    size_class = "large"
  } else {
    size_class = "small"
  }
  return(size_class)
}

Do Exercise 2 - First Commit, Exercise 3 - Importing Data, and Exercise 4 - Commit Multiple Files.

Git as a time machine

Experiment with impunity

get_size_class <- function(earlength, threshold){
  if (earlength > threshold){
    size_class = 1
  } else {
    size_class = 2
  }
  return(size_class)
}

Delete with impunity

GitHub Remotes

Draw diagram to link local machine with GitHub origin.

Push to a remote

Draw push arrow on diagram on board from local to origin.

Show local commit history and lack of history in remote.

Show local commits now on origin.

Do Exercise 6 - Pushing Changes.

Have students email a link to their repo to their instructor once they have finished Pushing Changes

The instructor should then commit the following code to their repo with the commit message: “Generate data frame with id and earlength class”

library(dplyr)

data_size_class <-
  data %>% 
  rowwise() %>% 
  transmute(id = id, earlengthcat = get_size_class(earlength, 10))

Collaborating

Show origin with collaborator commit.

Add collaborator local repo to diagram and pull arrow from origin to locals.

Show updates to history following Pull and run code

Do Exercise 7 - Pulling and Pushing.

Optional: Redraw diagram with local, origin, and upstream. Arrows from origin to/from upstream are pull requests and merges.

Show an example of a working repository with branches and forks. Navigate to pull requests.