Organize your research and teaching material with Git

Day 4/4: Collaborating on a GitHub repository

Waldir LeΓ΄ncio Netto

Research Software Engineer
Oslo Centre for Biostatistics and Epidemiology (OCBE)

https://github.com/ocbe-uio
https://github.com/wleoncio

Course plan (subject to change)

Day
Date
Focus
1
02 Nov
10:00-11:30
Git basics+ (status, add, commit, log, diff, reset, branch)
For all users, no matter how or where they work
2
09 Nov
10:00-11:30
Git + GitHub on RStudio (Stata/others get limited support)
Changing Git history (amend, squash, fixup)
3
16 Nov
10:00-11:30
Create and maintain a GitHub repository
(fetch, pull, push, issues, merge, rebase)
4 23 Nov
10:00-11:30
Collaborating on GitHub
(pull requests, forks, merge conflicts, blame)

Class rules (day 4)

Course slides

🌐 Available on https://ocbe-uio.github.io/public-slides/
πŸ“œ Licensed under Creative Commons Attribution-ShareAlike

Workflow

⁉️ At any time (in-person or chat)
πŸ’» Requirements: Git; GitHub account

Collaborating on a GitHub repository

...when you don't have write access to it

https://github.com/waldirln/nifu-course

Procedure

  1. Fork repository*
  2. Work
  3. Commit
  4. Create Pull Request*

* If you do have write access, forking is not necessary but PRs are a good way to practice peer-reviewing (even if you are the PI)

R-specific convenience packages

Procedure Browser CLI command R command
Fork βœ”οΈ gh repo fork usethis::create_from_github()
Add βœ”οΈ git add gert::git_add()
Commit βœ”οΈ git commit gert::git_commit()
Create PR βœ”οΈ gh pr create usethis::pr_init()

Notice the association:

  • GitHub commands: gh (🐧πŸͺŸπŸŽ) or usethis (R)
  • Git commands: git (🐧πŸͺŸπŸŽ) or gert (R)

Today's exercise: please join in!

  1. Try to contribute to https://github.com/waldirln/nifu-course
  2. Fork it
  3. Work on fork. Maybe try to cause file conflicts
  4. Contribute back (with a PR)

Resolving merge conflicts

  • On the browser, when possible
  • On your local machine, otherwise

Who did this?

  • git blame

Final takeaways

  • Git is a powerful tool for version control
  • GitHub is a powerful platform for backup and collaboration
  • You can use Git + GitHub for coding, writing, researching and teaching
  • You can use the command line (Bash, R) or graphical tools
  • Many text editors have GitHub integration (RStudio, VS Code)
  • You are going to forget commands, but you can always look them up