Version control systems + Git
Concepts in Git
Integration with Github
Create, collaborate, and share
Chacon, Scott, and Ben Straub. Pro git. Apress, 2014.
Image source: twitter.com/Linux/status/936877536780283905/photo/1
Rep - With Github, anyone with the right tools should be able to recreate your workflow Collabora
Local Version Control (L-VC):
Developed in response to error-prone manual VC
A database keeping track of file changes ("patches")
Patches can be added and subtracted to revert to documents in a certain state
Centralized Version Control (CVC):
Allows collaboration between systems
Files can be checked out from central server hosting database of file patches
Centralized server is weakness: If server goes down, VC/collaboration cannot occur
Distributed Version Control (DVC):
Users check out copies of full directories rather than individual files
These directories, or repositories, include the full history of each file
In short: everyone has the database of patches
Distributed Version Control (DVC):
Vocabulary check
Repository: A file directory that is being tracked by Git
Clone: An exact copy of a repository containing the full history of project changes
Files that have not been changed are not replicated, but linked to
All information is local, and all operations can be performed offline
When a snapshot is taken, a file is assigned an id specific to the checksum, or hash. No further changes can be made to that file without Git first knowing about it, and so you cannot lose information.
Files can be in one of three states after being added to repo
Staged - Files are marked for committing (the snapshot)
Modified - Staged files have been modified, but not committed
Committed - Snapshot taken, file states stored to local database
Local Git
Open command line or terminal window
Check user name and email address
git config --global user.name
git config --global user.email
Check text editor
git config --global core.editor
GitHub (remote Git)
Create Github account if you have not done so already
Log in!
Important that user name and email map to what you've used to sign up with on github
On windows, you will need to specify the full path to the executable file if changing text editor
Break out into groups of 3 or 4
Nominate group leader
Break out into groups of 3 or 4
Nominate group leader
Create a getting-git
repository on Github (gif below)
Group leaders: Allow group members to collaborate: Settings -> Collaborators -> [usernames]
From RStudio
Open RStudio and select File -> New Project
Select Version Control
Select Git
Paste https://github.com/[leader_username]/getting-git
into repo URL
Name your project getting-git
From cmd/terminal
Open command line or terminal
cd
into a directory where you want project to be housed
Enter git clone https://github.com/[leader_username]/getting-git
RStudio will automatically assign an Rproject file to your repository.
Vocabulary check
Commit: Git for "file save"
Remote: A repository not located on your local machine
In RStudio
Create a new file in /getting-git
(.R, .txt, etc)
Stage your file
Commit changes
Pull to download latest snapshot
Push to remote repository (Github)
In RStudio
Create a new file in /getting-git
(.R, .txt, etc)
Stage your file
Commit changes
Pull to download latest snapshot
Push to remote repository (Github)
From command line/terminal
Create new file in /getting-git
Stage your file:
git add [filename.xyz]
Commit changes
git commit
or git commit -m "[commit message]"
Pull to download latest snapshot
git pull
Push to remote repository (Github)
git push
Merge conflicts occur when collaborators overwrite each other's content
A merge conflict must be fixed manually
Merge conflicts occur when collaborators overwrite each other's content
A merge conflict must be fixed manually
Now for a well-orchestrated example
In your groups, force a merge conflict and work through it.
In someone else's document
Edit another group member's document
Stage, commit, and push the change
In your groups, force a merge conflict and work through it.
In someone else's document
Edit another group member's document
Stage, commit, and push the change
In your document (edited by someone else)
Make a change overlapping with group member edits. Stage and commit.
Pull from Github: a merge conflict will appear.
Fix conflict, stage, commit, and push!
In your groups, force a merge conflict and work through it.
In someone else's document
Edit another group member's document
Stage, commit, and push the change
In your document (edited by someone else)
Make a change overlapping with group member edits. Stage and commit.
Pull from Github: a merge conflict will appear.
Fix conflict, stage, commit, and push!
Assuming conflict exists between remote and local repos:
Add changes: git add [filename.xyz]
Commit changes: git commit -m "[going about my own business]"
Pull remote to prompt merge conflict: git pull
Fix conflict
Add changes, commit, and push!
Github Pages is a free service for hosting repository webpages
Some examples from EDAB:
SOE indicator visualizations:
Group leaders: Go to your repository setting and turn on Github Pages
Open up a new Rmarkdown document
Save it as "index.Rmd"
Knit the document to HTML
Stage, commit, and push index.html and index.Rmd to Github
Go to the url: [leader_username].github.io/[repository_name]
Once an index.html file has been push to the repo, more .html files can also be hosted
[username].github.io/[repository_name]/[paradigm_shifter.html]
Interactivity is easy:
library(dygraphs)
dygraph(nhtemp, main = "New Haven Temperatures") %>%
dyRangeSelector(dateWindow = c("1920-01-01", "1960-01-01"))
Add all files: git add .
Commit w/o text editor: git commit -m "Your commit message"
Show all settings: git config --list
View status of files in git repo: git status
View unstaged changes: git diff
View staged changes git diff --staged
View commit history git log
(pretty: git log --pretty=format:"%h - %an, %ar : %s"
)
Revert to commmit: git checkout [commit-ref] [filename.xyz]
From RStudio
Open RStudio and select File -> New Project
Select New Directory
Select New Project
Enter directory name and location
Select Create a git repository
From cmd/terminal
Open command line or terminal
cd
into a directory where you want project to be housed
Create folder for project mkdir [folder-name]
cd
into new directory
Initialize repository git init
Version control systems + Git
Concepts in Git
Integration with Github
Create, collaborate, and share
Chacon, Scott, and Ben Straub. Pro git. Apress, 2014.
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 |