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:
- Go to github.com and sign in
- Create a new repository
- Give the repository a good name
- Make the repository public, and add a readme file
- After pressing “create new repository”, Add your fellow group members to be collaborators
- 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
- Open RStudio and create a New Project from the RStudio project menu
- Chose “Version Control” and add the address to the repository
- Save your version of the project at a good location on your computer (What is a good location?)
- 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
- Add a quarto document called
my-report.qmd
to the root project folder. - Using GitHub desktop Student A commits changes (addition of the file) and push to the remote repository
Student B and C does
- In Github desktop, press “fetch origin”.
- 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:
- Add a table to the report, use the table created during homework (a solution can be found here)
- The table should be cross-referenced and displayed without the code (
#| echo: false
) - Commit changes with a message and push
Student C:
- Add a figure to the report, use the code from the homework as can be found here.
- The figure should have a label and cross-referenced without the code (
#| echo: false
) - 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
- In RStudio, find the
.gitignore
file and add a line that saysmy-files-studentA/
(if you play the part of student A), - In RStudio create a text-file and store it in a folder called
my-files/
- Commit changes and push.
- 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:
- In Github desktop, create a new branch, name it
new-branch
- Add a bibliography to the report (using the visual editor and a DOI of your choosing).
- Commit changes to the new branch.
- Go to GitHub.com and make a pull request.
- Review the change and merge the branches (on Github.com)
Using forks for changes
Exercise (5)
Student B and C:
- In Github desktop, fork the original repository to your own user profile
- Do a change to the repository
- Commit changes and create a pull request
- Student A reviews the pull requests.
Conflicts!
Exercise (6)
- Student A selects a specific line in the report and edits it, commits and push
- Student B (without first fetching), change the same line, commits and push.
- What does the error message say,
- Resolve the conflict and commit/push the final version.