Version control with git
Objective
- Understand the concept and motivation of version control
- Set up git on their machine (email address linked to their GH account;
--global
config) - Understand that repos == folders =can= .Rproj.
- Initialize a git repo associated with an RStudio project called
pilot-analyses
. - Understand the modify-add-commit progression. Apply this by making modifications to some R code and then committing it to the
pilot-analyses
repo (git commands:status
,log
,diff
,add
,commit
) - Use .gitignore to selectively exclude files from git.
Lesson outline
- Review of last week
- Ask folks to share the diagram of their file system
- Warm-up with review question from the slide deck
- Slides/lecture: Intro to version control with git
- What is version control?
- Why should I learn this? When will I need it?
- Live coding: git config
- SW Carpentry Git lesson 2 https://swcarpentry.github.io/git-novice/02-setup
- Setting up git using git config
- Make sure participants use their GH email/intended GH email
git
verb
options
git config --global core.editor "vim"
git
verb
--help
- Live coding: git init
- SW Carpentry Git lesson 3 https://swcarpentry.github.io/git-novice/03-create.html
- Introduce the concept of a repository
- Go over 3 ways to init a git repo and when to use each
- Break to all create a project + repo called pilot-analyses
- Live coding: git status
- Use git status to check that git init worked
- Talk about git status as a bridge to tracking changes.
- Live coding: Tracking changes
- SW Carpentry Git lesson 4 https://swcarpentry.github.io/git-novice/04-changes
- Visualize in slides
- Create a blank R file (using RStudio point and click)
- Make comments/pseudocode changes.
- git status
- Go through git add/commit cycle
- Repeat with additional changes, use git diff
- Repeat with multiple files
- Undo saved changes to a file using
git restore
- Use git reset HEAD~ to undo the git add and git commit commands
- Live coding:
.gitignore
- SW Carpentry Git lesson 6https://swcarpentry.github.io/git-novice/06-ignore
- .gitignore:
DS_Store
- Create a file and then ignore it.
- (Time permitting): SW Carpentry Git lesson 5
- https://swcarpentry.github.io/git-novice/05-history
- Navigating git history
- Homework:
- Create a GitHub account if you don’t have one.
- (Optional) identify an existing folder and turn it into a repository.
Installation & materials
Citation
BibTeX citation:
@online{scott2024,
author = {Scott, Eric and Diaz, Renata and Guo, Jessica and Riemer,
Kristina},
title = {Version Control with Git},
date = {2024},
url = {https://cct-datascience.github.io/repro-data-sci/lessons/4-git/notes.html},
doi = {10.5281/zenodo.8411612},
langid = {en}
}
For attribution, please cite this work as:
Scott, Eric, Renata Diaz, Jessica Guo, and Kristina Riemer. 2024.
“Version Control with Git.” Reproducibility & Data
Science in R. 2024. https://doi.org/10.5281/zenodo.8411612.