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

  • Download Gaeta_etal_CLC_data.csv.
  • Arrange to have a teaching partner attend class and push the following code for the ‘Collaborating’ demo.
ggplot(fish_data_cat, aes(x = scalelength, fill = length_cat)) +
  geom_histogram()
  • Open the following links in a browser and zoom in to make the images fill the screen.

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 and choose New repository.
  3. Choose the class organization (e.g., course-fish274-2019) as the Owner of the repo.
  4. Fill in a Repository name that follows the form FirstnameLastname.
  5. Select Initialize this repository with a README.
  6. Click Create Repository.

Connect to the Git repo in RStudio

  1. From new GitHub repository, click green Clone or download button -> Click the Copy to clipboard button.
  2. In RStudio, File -> New Project -> Version Control -> Git
  3. Paste copied URL in Repository URL:.
  4. Leave Project directory name: blank; automatically given repo name.
  5. Choose where to Create project as subdirectory of:.
  6. Click Create Project.
  7. Check to make sure you have a Git tab in the upper right window.

Do Exercise 1 - Set-up Git.

First commits

Commit data

Commit R script

fish_data = read.csv("Gaeta_etal_CLC_data.csv")

Building a history

library(dplyr)
fish_data_cat = fish_data %>%
  mutate(length_cat = ifelse(length > 200, "big", "small"))
fish_data_cat = fish_data %>%
  mutate(length_cat = ifelse(length > 300, "big", "small"))

Do Exercise 2 - First Solo Commit, Exercise 3 - Second Solo Commit, and Exercise 4 - Commit Multiple Files.

Instructor also do exercises

Git as a time machine

Experiment with impunity

fish_data_cat = fish_data %>%
  mutate(length_cat = ifelse(length > 300, "large", "small"))

Delete with impunity

GitHub Remotes

Push to a remote

Show local commit history and lack of history in remote.

Show local commits now on origin.

Do Exercise 5 - Pushing Changes.

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

The instructor should then commit the following code to their repo with the commit message: Plot histogram of scale length by fish categorical size

ggplot(fish_data_cat, aes(x = scalelength, fill = length_cat)) +
  geom_histogram()

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 Tasks 3-6 in Exercise 6 - 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.