Overview

Teaching: 30 min
Exercises: 15 min
Questions
  • How can we use Git and GitHub in Rstudio

Objectives
    1. “become familiar with Rstudio’s Git and GitHub integration”

Requirement

Follow along demo:

  1. Fork the rr-version-control-demo repository.
  2. Clone your forked repository to obtain a local copy of the files into an RStudio project.
  3. Edit a file in this repository/project.
  4. Stage your changes to be committed.
  5. View the diff, and commit your changes, with a commit message.
  6. Push your changes to your own fork of the the rr-version-control-demo GitHub repository.

Step 1: Fork:

Fork the rr-version-control-demo repository.

  1. Go to the repository at https://github.com/Reproducible-Science-Curriculum/rr-version-control-demo.
  2. Click on “Fork”” (on the top right corner).

Now you have a copy of rr-version-control-demo repository in your account, woohoo!

Aside: Where am I?

How can I tell if I am looking at my fork or the original repository?

Step 2: Clone

Clone your forked repository to obtain a local copy of the files .

  1. In RStudio, go to “File > New Project”
  2. Click on “Version Control: Checkout a project from a version control repository
  3. Click on “Git: Clone a project from a repository
  4. Fill in the info:
    • URL: use HTTPS address
    • Create as a subdirectory of: Browse to where you would like to create this folder

Step 3: Edit

Edit a file in this repository/project.

  1. Open the file called gdp-life-expectancy.Rmd and knit.
  2. Change the analysis_year to another year for which we have data (1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, 2002, 2007), and knit again. Examine the output for changes.

Step 4: Stage

Stage your changes to be committed.

  1. Go to the Git pane in RStudio.
  2. Stage the changes for gdp-life-expectancy.Rmd and gdp-life-expectancy.html by checking the boxes next to then, and hit Commit.

Don’t worry about the other files that appear in this pane, we’ll get to them in a bit.

Step 5: Commit

View the diff, and commit your changes, with a commit message.

  1. In the pop-up window view the diff for the .Rmd file. You can view it for the .HTML file as well if you like.
  2. Enter an informative commit message, like “Changed analysis year to X”, and hit Commit.

Step 6: Push

Push your changes to your own fork of the the rr-version-control-demo GitHub repository.

push: When using git push always means pushing commits from your local respository (your computer) to a remote repository (GitHub).

  1. Now push your changes to GitHub by hitting Push.
  2. Enter login information as needed.

Getting an error? Can’t push? See here under GitHub password. Ask a helper!

More info on the Git pane

File tracking:

You can get more details about modifications with a :

What’s in my Git pane?

Key Points