This document will assume that you’re already familiar with GitHub. If you need a primer on what GitHub is and how to use it, Lynda’s got you covered. Use your St Olaf credentials to log into Lynda.com– click here for more information.
Using version control in your R projects can be a good idea, especially if you have multiple people contributing to your project. Here’s how to get started with GitHub for your RStudio Pro project. Start by creating a repository on GitHub with your GitHub account, and keeping the URL for your repository handy.
Note that not all GitHub repositories are private, and you may need a private repository for your work. You can request a free upgrade to your GitHub account with a Student Developer Pack, which will give you unlimited private repositories. If you’re a faculty/staff member and need to upgrade your GitHub account, go to GitHub for Education’s Discount Request page (requires GitHub login).
Other users can also make you a collaborator in their private GitHub repositories as well; and they can provide you with the right URL you’ll need.
- Go to r.cs.stolaf.edu and log into RStudio Server Pro with your St Olaf credentials.
- Start a new project: File > New Project. Then select Version control at the bottom.
- Next, choose Clone a project from a Git repository
- Now, we have a bit of work to do. You’ll need to have already created a repository on GitHub and have the URL available. Copy it from GitHub and paste it in the Repository URL as seen below. The project directory name will autofill from the URL. The ~ in the Create project and subdirectory of: means to create a new folder in your linux home directory on r.cs.stolaf.edu. The folder will be visible under the Files tab in your home directory. When ready, click on the Create Project button.
- Your project will be created, and RStudio will switch over to your new project. Note there’s a new tab in the Environment/History panel for Git:
- At this point, if you’re familiar with Git, you’re pretty much ready to go. Except there’s a couple more things left to do. before you do a push or pull, you’ll need to commit your changes. The first time you do a commit, you’ll see an error screen as below:
- You’re seeing this because the linux account that gives you access to RStudio lacks a small file in your home directory called .gitconfig. This tells Git on the RStudio server who you are. The error window is in fact telling you exactly what you need to do to create a .gitconfig account in your home directory yourself. For the most part, you don’t have access to the linux shell that RStudio Pro runs in; you interact with your files and projects completely through RStudio Pro. However, you can use RStudio to get enough access to linux to create a .gitconfig file. In RStudio, under the Tools directory, choose Shell…
- Once you do this, a pop-up window will open in RStudio, giving you limited shell access to linux on the RStudio server. You’ll have a prompt that ends in a $. From here, simply enter the two commands in the original error message, hitting return after each command (no error message after hitting return means that the command was accepted):
git config --global user.email "<your email address>" git config --global user.name "<your name>"
… just make sure to customize the information inside the quotes to whatever email address you care to use, and your full name.
- You now have a valid .gitconfig file in your home directory, and you’ll be able to commit, push and pull from GitHub. Note that when you do a git push or pull, you’ll need to provide your GitHub username and password through RStudio to authenticate that you’re allowed to access the remote repository.