Before class

  • Setup class organization at Github
    • Check the Allow members to create repositories for this organization permission
    • Set the Default permissions for the organization to None if you want to avoid students accessing each others repositories
  • Have students create a GitHub account and email their username to the instructor.
  • Add students’ username to organization.

For class

  • Download Gaeta_etal_CLC_data.csv.
  • Either arrange to have a teaching partner to attend class or be logged into GitHub as another user in the browser for collaboration demos.

  • Open the following links in a browser and zoom in to make the images fill the screen.

Live coding demo and assignment are intertwined and designed to work in order.

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., 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. 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.

Introduce yourself to Git

  1. Git tab -> More -> Shell
  2. git config --global user.name "[name]"
  3. git config --global user.email "[email]" (same as GitHub account email).

That was Exercise 1 - Set-up Git. Have students confirm that this all worked and fix any issues.

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

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 5 - 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: Plot histogram of scale length by categorical size

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

Either you (logged in as another user) or your teaching partner should make the same change to your respository

Pulling

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.

Merges

Demo merges either with a partner or by logging into GitHub as another user in the browser.

geom_histogram(bins = 10)
filter(scalelength >= 0.5)

Merge conflicts

mutate(length_cat = ifelse(length > 300, "large", "small"))
mutate(length_cat = ifelse(length > 250, "big", "small"))
mutate(length_cat = ifelse(length > 250, "large", "small"))

Full GitHub flow

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.