git and R

RaukR 2024 • Advanced R for Bioinformatics

Sebastian DiLorenzo

21-Jun-2024

Overview

  • What is git and why should I use it?
  • git set-up
  • git for yourself
  • git with github
  • Summary

What is git and why should I use it?


  • Track changes
  • Revert changes
  • Reproducibility
  • Backups
  • Working with others

What is git and why should I use it?


Version control

In software development, version control is a class of systems responsible for managing changes to computer programs or other collections of information such that revisions have a logical and consistent organization.

https://en.wikipedia.org/wiki/Comparison_of_version-control_software


Repository

A collection of files under version control.

git set-up


Checking configuration

usethis::git_sitrep()

git set-up


Checking configuration

usethis::git_sitrep()
Git config (global)
• Name: 'Sebastian-D'
• Email: 'dilorenzo.sebastian@gmail.com'
Global (user-level) gitignore file: <unset>
• Vaccinated: FALSE
ℹ See `?git_vaccinate` to learn more
• Default Git protocol: 'https'
• Default initial branch name: <unset>
GitHub
• Default GitHub host: 'https://github.com'
• Personal access token for 'https://github.com': '<discovered>'
• GitHub user: 'Sebastian-D'
• Token scopes: 'repo, user, workflow'
Email(s): 'dilorenzo.sebastian@gmail.com (primary)', 'sebastian.dilorenzo@scilifelab.uu.se'
Git repo for current project
• Active usethis project: '/Users/sd/Library/CloudStorage/Box-Box/Work/NBIS_CommMan'
ℹ Active project is not a Git repo

git set-up


Setting global configuration

usethis::use_git_config(user.name = "Jane Doe", user.email = "jane@example.com")

git set-up


Personal Access Token (PAT)

  • Credentials
  • Scope
    • “What is this PAT allowed to modify?”
  • No password prompt when uploading/downloading data.
#Takes you to github.com create new token.
usethis::create_github_token()

#Use to set your new token in your configuration
gitcreds::gitcreds_set()

git for yourself

git for yourself

Workflow:

  • Make some changes.
  • git add the new or changed files.
  • git commit the current state of repository.

git for yourself

Useful commands:

  • git status lists changes in your repository.
  • git diff shows the difference between a file and its last commit state.
  • git reset go to a previous commit state.
  • usethis::use_git(), initialize git in a project that did not have git activated.

git with github

  • git clone, copy the github repository to a local repository.
  • Create a repository on github from your current RStudio git repository: usethis::use_github()
  • git push your local file changes to the github repository.
  • git pull the github repositories file changes to your local repository.

git with github

Working with others workflow

1. pull changes made by others from github repo.
2. Settle eventual merge conflicts.
3. Make own changes.
4. add and commit changes.
5. Repeat 3 and 4 as necessary.
6. push changes to github, sharing them with others.

Summary


git and github are great for structured, reproducible, collaborative work.


  1. Create a folder.
  2. Make it a RStudio project.
  3. Make it a git repository.
  4. Connect it to github.
  5. Profit.


commit often, push/pull less often.

Thank you! Questions?

         _                     
platform aarch64-apple-darwin20
os       darwin20              
major    4                     
minor    4.0                   

2024 • SciLifeLabNBISRaukR