Main content

Home

Menu

Loading wiki pages...

View
Wiki Version:
## How to use GitHub as version control for RStudio and as an add-on in OSF Author: [Joss Ives][1] Sources: [1][2], [2][3] ## Software First you need to install the following software: * R: [https://cran.r-project.org/mirrors.html][4] * RStudio: [https://www.rstudio.com/products/rstudio/download/#download][5] * Git: [https://git-scm.com/downloads][6] You will also need to have a GitHub account: * [https://github.com/][7] ## Setup Git on RStudio and associate with GitHub In RStudio, choose *Tools => Global Options* and then choose the *Git/SVN* tab. Double-check that the *Git Executable* points correctly to the executable. @[osf](fmvha) Now we create an RSA key in RStudio and provide it to GitHub. First, click on the *Create RSA Key* button. In the popup window click on *Create* (no need for a passphrase). In the next popup window click on *Close*. @[osf](85wur) Back in the original window, click on *View public key* and then copy the key to the clipboard. @[osf](epzmh) We will now enter the key on GitHub. Over on GitHub, go into *Settings*. @[osf](764er) Click on *SSH and GPG keys* and the *New SSH Key* button. Choose a *Title* and paste the key into the *Key* box. Then click on *Add SSH Key*. You will likely be prompted to enter your GitHub password. @[osf](aqr6j) ## Give Git on your computer your GitHub credentials Open a command window (Windows key and then type *cmd*) and then enter your GitHub email and username: ``` git config --global user.email "tipsy@mcswagger.com" git config --global user.name "jossives" ``` ## Make a repository on GitHub and then create a new RStudio project from this repository Make a new repository on GitHub. @[osf](hn6mp) Name your repository (*osf-rstudio-github-test* if you like) and then check the *Initialze the repository with a README* checkbox (GitHub will suggest strongly to you that you need one after the fact so you may as well do it now). @[osf](7dp9b) Head on back to Rstudio and start a new project: *File => New Project*. In the popup window choose *Version Control* to associate the new project with your just-created repository on GitHub. @[osf](8w4fy) On the next screen, choose *Git*. On the screen that follows you, enter the URL for your previously-created GitHub repository (it is likely the GitHub page your browser is currently on). Then click *Browse* and choose where on you local machine you would like this new project to be saved to. @[osf](5bkx8) ## Commit and push your first changes In RStudio you should now see that you have 3 files in your active directory in the *Files/Plots* panel. We are going to commit to Git and then push to GitHub the files that are new since we first created the repository. Click on the *Git* tab in the *Environment/History* panel and check the boxes for all of the files showing. Then press the *Commit* button. These files are all ones that have changed since the last commit to Git. @[osf](xpc5w) In the popup window, type an initial commit message and then click the *Commit* button. Close the popup windows. @[osf](v85x2) Finally, push the committed changes to GitHub by clicking the *Push* button (with a green up-arrow) in the *Git* tab in the *Environment/History* panel. @[osf](gpu32) ## Create a new file (notebook) in RStudio and then *Commit* and *Push* the changes Create a new notebook. @[osf](75f6m) Save the notebook as *notebook-test* (or whatever you like). In the *Git* tab of the *Environment/History* panel, you will find the files associated with the notebook. *Commit* and *push* these new/updated files. @[osf](rfbz5) After you *push* the commited changes, you will see them on GitHub. @[osf](atyx5) [1]: http://osf.io/ntqkw [2]: https://www.r-bloggers.com/rstudio-and-github/ [3]: https://support.rstudio.com/hc/en-us/articles/200532077-Version-Control-with-Git-and-SVN [4]: https://cran.r-project.org/mirrors.html [5]: https://www.rstudio.com/products/rstudio/download/#download [6]: https://git-scm.com/downloads [7]: https://github.com/
OSF does not support the use of Internet Explorer. For optimal performance, please switch to another browser.
Accept
This website relies on cookies to help provide a better user experience. By clicking Accept or continuing to use the site, you agree. For more information, see our Privacy Policy and information on cookie use.
Accept
×

Start managing your projects on the OSF today.

Free and easy to use, the Open Science Framework supports the entire research lifecycle: planning, execution, reporting, archiving, and discovery.