This tutorial is a quick start guide to sharing your code on github using Rstudio. Command line is optional.
Similar to ‘track-changes’ in Microsoft Word, Git keeps track of any edits and makes it possible to track who made the change and when. Git is most commonly used to manage collaboratively edited code, but it can keep track of any file.
Payoffs
Costs
RStudio ‘projects’ make version control & document preparation simple
Payoffs - Free space for hosting (and paid options) - Assignment of persistent DOIs - Tracking citation metrics
Costs - Sometimes license restrictions (CC-BY & CC0) - Limited or no private storage space
You can think of GitHub as part:
sudo apt-get install git
or similar
* Add a brief and informative description * Choose “Public” * Check the box for “Initialize this repository with a README” 3. Click “Create Repository”
clone
the repositoryGo to RStudio
Fill in the info:
The 3 states of files: Staged, Modified, Committed
The important stuff is hidden in the .git
folder (which might be hidden on your computer)
Select which changed files (added, deleted, or edited) you want to commit. Staging allows you to choose just a certain subset of modified files to associate with a commit. (If you always save all your changes in the same commit, this maybe isn’t intuitive…)
Add a commit message and click commit.
push
)Click the green arrow to sync with GitHub.
Try adding the Rmd (and associated .md, R, files) you created in the last tutorial (or any other Rmd) to your working folder and push it to github.
In case you don’t have one handy, use this the R Script associated with this page is available here.
Now add another github user to your repo (e.g. the person sitting next to you).
Practice modifying a file and pushing it to one another’s repos.
A conflict can occur if two people simultaneously edit the same file and haven’t pushed it. This can be resolved by merging if the bits of code don’t overlap, but requires someone to choose which version of the code to keep if they do overlap. Either avoid working on the same bits of code simultaneously, or read on to learn more advanced git functions.
RStudio has limited functionality.
$ git help <verb>
$ git <verb> --help
$ man git-<verb>
For example, you can get the manpage help for the config command by running git help config
Similar to info in git tab in RStudio
git config
shows you all the git configuration settings:
user.email
remote.origin.url
(e.g. to connect to GitHub)Branches used to develop features isolated from each other.
Default: master branch. Use other branches for development/collaboration and merge them back upon completion.
$ git checkout -b devel # create new branch and switch to it
$ git checkout master #switch back to master
$ git merge devel #merge in changes from devel branch
But we won’t do much with branching in this course…
Take 15 minutes or so at this site to walk through some basic git commands
Remember, the data and code are real, the products (tables, figures) are ephemeral…