ETC5513: Collaborative and Reproducible Practices

Tutorial 5

Author

Michael Lydeamore

Published

21 May 2024

🎯 Objectives

  • Create a repository in GitHub
  • Create branches
  • Merge
  • Work with .gitignore files

Exercise 1: Git practice

  1. Log into your GitHub account

  2. Fork the following repo: https://github.com/ETC5513-2024/Tutorial-Branches

  3. Clone this onto your computer

  4. Open README.md in RStudio and delete any text that is inside the file. Using markdown language, add a heading with the title “This is tutorial 5”.

  5. Stage, commit and push the changes to the remote repository into GitHub

  1. In the same README.md, add the following after the title: “In this tutorial we are learning to use git rebase, to create a .gitignore file and to collaborate with others.”

  2. Commit and push the changes to the remote repository in GitHub.

  3. Go to GitHub and make sure you have two commits in your repo history.

  4. Create a new branch called “Tutorial5-Exercise1”. Checkout that branch and make sure you push the changes into the remote repository using git push -u origin Tutorial5-Exercise1.

Tip

Remember if you create the branch inside RStudio it will automatically be pushed to the remote repo in GitHub

  1. Create a file called Tutorial5.qmd on the Tutorial5-Exercise1 branch that contains the following:
  • Title: Learning to merge
  • Author: [insert your name]
  • Date information
  • The file will render to HTML
  1. Stage, commit and push the changes to the remote repo in GitHub. Then, merge the changes in your new branch into the main branch.

  2. Swap to the main branch and add the following into Tutorial5.qmd:

library(tidyverse)
library(palmerpenguins)

data(package = "palmerpenguins")

ggplot(penguins, aes(x = bill_depth_mm, y = flipper_length_mm, color = species)) +
    geom_point()
  1. Stage, commit and push the changes into main in your remote repo
  1. Add the following into Tutorial5.qmd:
ggplot(penguins, aes(x = species, y = bill_length_mm, fill=species)) +
geom_boxplot(outlier.colour = "blue", outlier.size = 2) +
geom_jitter(width=0.2, alpha = 0.5) +
labs(title="Penguin Bill Length") +
theme_light()
  1. Create a new file called ignoring.txt and a new file called .gitignore using touch. Make sure the files are create in your repo using ls -a. State these files, commit and push them.

  2. In RStudio, open the .gitignore file and edit it to add a rule to ignore files with extension *.txt.

  3. Stage, commit and push the changes into main in your remote repo.

  4. Inspect your git tree using the diff window in RStudio

  5. Optional: Rebase the commits in your branch Tutorial5-Exercise1 into mmain and have a look at the git tree. Then, merge Tutorial5-Exercise1 into main and have a look at the git tree.

Exercise 2: Collaboration with pull requests

  1. Exchange your GitHub repo details with your partner for this exercise

  2. Fork each other’s repositories in your GitHub and clone a local copy

Important

You may have to rename the fork when you do this. Put either your initials or your partners in the repo name to distinguish it.

  1. Create a new branch and work on this branch.

  2. Add a new section and a figure into the report.

  3. Stage, commit and push the changes into your remote repo in GitHub.

  4. Once you have finished with all the changes, merge your new branch into main.

  5. Create a pull request explaining the changes.

  6. Revise the pull request and accept the proposed changes.

  7. Solve any possible conflicts and merges changes into your original repo that you created in Exercise 1.

  8. If you have more time, repeat this exercise with more complicated changes. See if you can deliberately create a merge conflict!