Writing version controlled reports

Introduction

Creating an empty project (GitHub first)

Exercise (1)

In groups of three (Student A, B and C), work together and help Student A to:

  1. Go to github.com and sign in
  2. Create a new repository
  3. Give the repository a good name
  4. Make the repository public, and add a readme file
  5. After pressing “create new repository”, Add your fellow group members to be collaborators
  6. All group members must accept the invitation to the repository
  • Your new github project is now ready to be downloaded into an RStudio project.
Exercise (2)

Student A, B and C all do the same steps on their own computer

  1. Open RStudio and create a New Project from the RStudio project menu
  2. Chose “Version Control” and add the address to the repository
  3. Save your version of the project at a good location on your computer (What is a good location?)
  4. Open Github Desktop and add the local repository (your local folder) to your list of repositories
  • All group members have downloaded a copy of the original repository, we will start making changes and see how we can “share” them across group members.
Exercise (3)

Student A performs the following steps

  1. Add a quarto document called my-report.qmd to the root project folder.
  2. Using GitHub desktop Student A commits changes (addition of the file) and push to the remote repository

Student B and C does

  1. In Github desktop, press “fetch origin”.
  2. Inspect what changes occurred in Files in R Studio.
  • Next we want to add different content to the report. We will do this simultaneously and see how git manages this.
Exercise (4)

Student B:

  1. Add a table to the report, use the table created during homework (a solution can be found here)
  2. The table should be cross-referenced and displayed without the code (#| echo: false)
  3. Commit changes with a message and push

Student C:

  1. Add a figure to the report, use the code from the homework as can be found here.
  2. The figure should have a label and cross-referenced without the code (#| echo: false)
  3. Commit changes with a message and push

Student A: 1. Fetch origin and inspect changes

Git ignore

  • Sometimes you would like to store information in your folder locally that is not meant to be version controlled
  • Git ignore can make this possible
Exercise (4)

All group members

  1. In RStudio, find the .gitignore file and add a line that says my-files-studentA/ (if you play the part of student A),
  2. In RStudio create a text-file and store it in a folder called my-files/
  3. Commit changes and push.
  4. Fetch any changes and inspect what happens to your repo.

Using a branch for a large change

  • Branches are different from forks as they are parallel copies of the main working branch
  • A branch can be used to introduce some new feature to the repository which needs more attention.
Exercise (5)

Student A:

  1. In Github desktop, create a new branch, name it new-branch
  2. Add a bibliography to the report (using the visual editor and a DOI of your choosing).
  3. Commit changes to the new branch.
  4. Go to GitHub.com and make a pull request.
  5. Review the change and merge the branches (on Github.com)

Using forks for changes

Exercise (5)

Student B and C:

  1. In Github desktop, fork the original repository to your own user profile
  2. Do a change to the repository
  3. Commit changes and create a pull request
  4. Student A reviews the pull requests.

Conflicts!

Exercise (6)
  1. Student A selects a specific line in the report and edits it, commits and push
  2. Student B (without first fetching), change the same line, commits and push.
  3. What does the error message say,
  4. Resolve the conflict and commit/push the final version.