+ - 0:00:00
Notes for current slide
Notes for next slide

Introduction to Git and GitHub with RStudio

Olivier Gimenez

last updated: 2021-03-21

1 / 31

Credits

2 / 31

Rings a bell?

3 / 31

Version Control

What is it?

The management of changes to documents, computer programs, websites, etc...

Git

Free to use version control software

If Dropbox and the "Track changes" feature in MS Word had a baby, that would be Git (Alexa Fredston)

GitHub

A website (https://github.com/) to store your Git repositories online and makes it easy to collaborate with others

You do not need GitHub to use Git, just like you do not need RStudio to run R (Alexa Fredston)

4 / 31

Git, Github & RStudio

Before: Git only through the terminal 😢

6 / 31

Git, Github & RStudio

Before: Git only through the terminal 😢


Now RStudio allows using Git & GitHub 🤩

6 / 31

Configure Git & GitHub

Configure Git

Check your configuration

usethis::git_sitrep()

Set your configuration

Use your github username and the email you used to sign-up on GitHub

usethis::use_git_config(
user.name = "oliviergimenez",
user.email = "olivier.gimenez@cefe.cnrs.fr")
7 / 31

Configure GitHub authentication

Get GITHUB Personal Authorisation Token

usethis::create_github_token()

8 / 31

Store in .Renviron file

usethis::edit_r_environ()

9 / 31

RStudio Projects

Use RStudio projects to keep materials associated with a particular analysis together


  • Self contained and portable
  • Working directory set to root of project on launch
  • Fresh session everytime the project is launched

See Jenny Bryan's post on project oriented workflows for more details

File > New Project > New Directory

10 / 31

Initialise git

Initialise RStudio project with Git by just checking a box!

It's now a repository

11 / 31

Git panel

Integrated graphical user interface


12 / 31

Git terms

  • repository your project folder
  • commit a snapshot of your repo
  • push send commits to a remote
  • pull get commits from a remote


  • (clone get the repository from the remote for the first time)
  • (branch a movable label that points to a commit)
  • (merge combining two branches)
  • (remote a computer with the repository on it)
13 / 31

Git RStudio workflow

view file status

stage files

commit changes

14 / 31

Share on GitHub

Create repo

Via GitHub or using package usethis w/ usethis::use_github(protocol = "https")

Push further changes

15 / 31

Anatomy of a GitHub repo

  • README. Explain what your project is, and how to use it.

    • usethis::use_readme_md()
    • usethis::use_readme_rmd()
  • LICENSE. Without a licence, the contents of the repository are technically closed.

    • Examples licence MIT: usethis::use_mit_license(name = "Olivier Gimenez")
    • ?licenses: details of functions available to generate licenses
    • https://choosealicense.com/ help on choosing a licence.
16 / 31

Anatomy of a GitHub repo

  • CONTRIBUTING.md - guidelines for contributors.

    • usethis::use_tidy_contributing() provides a realtively strict but instructive template
  • CODE_OF_CONDUCT.md set the tone for discourse between contributors.

    • use_code_of_conduct()
17 / 31

GitHub issues

Use so-called issues to plan, record and discuss tasks

18 / 31

Why using a remote like GitHub ?

  • A backup of your repository

  • Keep track of all changes, and possibility to rollback to a previous state

  • Increase your visibility

  • Easy distribution of packages (without CRAN submissions)

  • Work with others (not [fully] covered)

  • Increase interactions with users (issues, pull requests)

19 / 31

Working with others

  • Use issues to talk to repo holders: propose changes, report bugs, etc...

  • If you're a collaborator, clone the repo, do modifications and push them

  • If you're not a collaborator, fork, clone then use pull requests

  • Branches allow playing around without messing around with the main line of development

    • Allow exploring several versions of an idea, and switching between them
    • A branch should correspond to a bug fix, a new feature, etc.
    • Useful when unsure when/if some modifications will be included

  • Resolving conflicts: see practical
20 / 31

My two-cent workflow



22 / 31

Create a new repository on GitHub



23 / 31

Name and Public/Private

24 / 31

Copy https



25 / 31

In RStudio, File/New Project



26 / 31

Select Version Control


27 / 31

Select Git



28 / 31

Clone your repo (remote to local)

29 / 31

Stage, commit and push



30 / 31

Alternative is to go local first


  • Step 1: Use RStudio projects (possibility to create a project from an existing directory)

  • Step 2: usethis::use_git() and follow instructions

  • Step 3: usethis::use_github() and follow instructions

31 / 31

Credits

2 / 31
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow