Associate Professor of Sociology at the City University of New York, Queens College

Getting Started with GitHub and RStudio

Use Github to track and share your R scripts

GitHub is an online code repository that is maintained by Microsoft. It is an excellent, free-to-use repository that allows you to save, update, and share scripts and output. It is useful for many things, including:

  • Version control, keep track of old versions of your scripts and track how you have updated them.
  • Code repository, a useful system for storing and disseminating code. It is an effective way to distribute programs or allow people to check your work.
  • Collaborative coding, upload your work on a collaboratively-coded script or download your colleagues’ recent work. Helps prevent a situation in which a team is working on different versions of a script

I’m sure that there are other great uses. If you want to share ideas with your colleagues, you can add them below in the comments section.

This tutorial is adapted from a tutorial from the University of Chicago. Readers should visit that site for a more detailed walk-through.

Start a Git Repository

On GitHub.com, create a “New Repository” (look for a green button). Click the green button to start an archive

Create a new repository. Make the repository public, and initialize it WITH a README file.

Create a Project Connected to the Repository

Click File > New Project > Version Control > Git

Click Version Control
Choose Git

You will then be asked for this information. In the bottom field, name the folder that will contain your new project folder. In the middle field, give your project a name. The top field requires the URL for this project’s associated Git.

Empty Info Box

You can get the address for your Github repostory by visitng the repository, clicking the green button, and getting the HTTPS clone address. Add that address to the top line.

Get Your Repository Address from Github

Complete the information to create the R Project file.

Filled Out Form

You have now created a project. It will remember the state of your RStudio session when you exit, and will bring it up again when you open the project again in the Project menu:

The Project Menu

Push Your Scripts or Script Changes to GitHub

Select the file you wish to upload, and click “commit”

Stage Your Script

Fill out the popup window. Write a comment and click “Commit”. Then “Push”

Et voila!, your script is posted to GitHub!

Pulling a Repository

Want to see if someone changed your repository while you were away? Press the “Pull” button in the Git window:

Click Pull to Download Changes

Leave a Reply

Your email address will not be published. Required fields are marked *