For R software development
Christopher Gandrud
9:30-10:30
Git/GitHub for R Software Development
10:30-12:00
Developing Statistical Software using IQSS Best Practices
a system that records changes to a file or set of files over time so that you can recall specific versions later
https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control
Oh No!
A
B
C
A
B
C
A
No Problem
Oh No!
# in R
devtools::install_github("username/reponame")
A directory that has been "initialized" so that git can record changes made to files within it.
Often shortened to "repo".
An initialized repository has a .git file in it.
Adding files to the git index allows you to commit them. . .
. . . What is commit?
Record changes to a repository
A
B
C
Examine changes between commits
A lineage of commits
The "main" history of commits, usually thought of as "stable"
You can work on multiple branches at the same time.
Switch to a different branch
Note: make sure you have committed all changes before checking out a branch
Join two or more branches (histories)
When merged branches have different changes on the same line of code, a conflict is created
You must determine how to resolve merge conflicts and then commit the changes
A git repository stored on a local machine
A git repository stored remotely
(e.g. on GitHub)
Updating a local repository with changes in a remote repo
Updating a remote repository with changes in a local repo
Copy a repo into a new directory
Copy a repository (without the ability to commit changes to the original)
Request to update a remote repo with changes from a fork
Install GitHub Desktop: https://desktop.github.com/
Terminal
Rstudio
# change to directory you want to store the repo in
cd [WHERE YOU WANT THE REPO]
# make new directory
mkdir NewRepo
# git initialize
cd NewRepo
git init
File > New Project
It's Always good to have a Readme.md file explaining the who, what, why, and how of the repo
# NewRepo
[YOUR NAME]
## Motivation
This repository is a test.
It's should be written in Markdown with a text editor (like RStudio)
Terminal
git add .
git commit -am "new README"
RStudio
Stage and click commit
Terminal
git remote add origin https://github.com/USERNAME/NewRepo.git
git push -u origin master
RStudio
git remote add origin https://github.com/USERNAME/NewRepo.git
git push -u origin master
Add GitHub Username and Password
Terminal
After saving changes to a file...
git add .
git commit -am "second commit"
git push origin master
RStudio
Stage and click commit
Commit
Push
Terminal
RStudio
git branch
GitHub
Terminal
RStudio
git checkout -B NewBranch
[Daily Build Version: https://dailies.rstudio.com/]
You can also sync the branch with GitHub by pushing as before. Just change the name from master to the branch name
Terminal
RStudio
Make sure you have committed all changes
# switch back to master
git checkout master
# merge NewBranch
git merge NewBranch
# switch back to master
git checkout master
# merge NewBranch
git merge NewBranch
Add their Username
Both of you make changes to the repo, commit them, and push the changes.
The collaborator may want to make changes on GitHub or clone the repo locally.
Before you can push, you may need to pull your collaborator's changes.
Terminal
RStudio
git pull origin master
both of you make changes to the same line of the same file and try to sync with the remote.
Merge conflict in README.md, so . . .
Open README.md
Delete what you don't want to keep.
Save, commit and push.
The local version
The remote version
This hash uniquely identifies a commit
R package development best practices at 10:30