February 9, 2017
All source code at https://github.com/rladies/rtp_20170209_rgitgithub
Slides at http://rpubs.com/mine/rladies-git
PhD Comics
Simple formal system for tracking all changes to a project
Learning curve is steep, but when you need it you REALLY need it
Your closest collaborator is you six months ago, but you don't reply to emails.
– Paul Wilson, UW-Madison
Username tips:
Stay current!
sessionInfo() to check your R versionIn RStudio, Tools -> Shell
This will take you to the shell in your current directory
Go to the shell. Enter which git to request the path to your Git executable:
which git
## /usr/bin/git
and git --version to see its version:
git --version
## git version 2.6.4 (Apple Git-63)
IF NOT: See http://happygitwithr.com/install-git.html or follow along with someone near you who has git installed.
We want to let git know who we are so there are some simple configuration options we should setup.
Let's first tell git who we are, and what editor we want to use.
$ git config --global user.name "Mine Cetinkaya-Rundel" $ git config --global user.email "mine@stat.duke.edu" $ git config --global core.editor nano $ git config --global --list
user.name does NOT have to be your GitHub username, although it can be. Another good option is your actual first name and last name. Your commits will be labelled with this name, so this should be informative to potential collaborators.user.email must be the email that you used to sign up for GitHub.Make sure to put this information in your github profile as well.
Go to https://github.com and make sure you are logged in.
Click green "New repository" button. Or, if you are on your own profile page, click on "Repositories", then click the green “New” button.
Repository name: myfirstrepo (or whatever you wish, we will delete this)
Public
YES Initialize this repository with a README
Click big green button "Create repository"
Copy the HTTPS clone URL to your clipboard via the green "Clone or Download" button
In RStudio
File -> New Project…
Git
Fill in Repository URL, project name (what you want the folder to be called locally), browse to where you want this folder to live
README.md file in RStudio
Go to the Git tab and view the Diff
Check box next to README.md to Stage: Makes git aware of the current version of both files, but we have not actually saved the changes yet.
Hit Commit to save the changes (locally)
These files got created when you created the R project
.gitignore lists files that won't be tracked by git
*.Rproj is the R project information
EXERCISE:
Stage, commit, push both
Review your commit on GitHub
git config credential.helper cache in shellgit config credential.helper 'cache --timeout=300' reduces caching to 5 minutesOption 2: Credential caching for HTTPS access http://happygitwithr.com/credential-caching.html#credential-caching
Option 3: Set up SSH keys http://happygitwithr.com/ssh-keys.html#ssh-keys
Create a new R Markdown file (just the example template will do)
Knit HTML
Stage, commit, push, review commit on GitHub
Want to see your results/graphs on GitHub? Use output: github_document instead.
What if at the same time a collaborator was making changes to the same file?
On GitHub:
In RStudio:
github README status
Before you can push, you'll need to pull
And then resolve the merge conflict
Finally you can push
Stage -> git add
Commit -> git commit
Push -> git push
Pull -> git pull
Above materials are derived in part from the following sources: