Ready to stop e-mailing code to your collaborators? Want a better way of keeping track of the changes you make on your programming projects? The Git system is designed to make collaboration easier and more transparent. This lesson provides an introduction to the version control system Git, one central sharing point called GitHub, and how you can use the two in RStudio.
The oft-asked question: What is the difference between Git and GitHub? has a relatively simple answer.
Git was originally developed for keeping track of changes in computer programming code, but is now used for much more, including open access journals, blogs, and text books.
Throughout the rest of the lesson, you’ll see the word “repository” (or “repo”, for short). A repository can be considered a storage system (like a folder on your computer) where your work is kept.
Make sure you have R and RStudio installed on your machine.
You’ll need to have Git installed to take advantage of this version control functionality. To see if you have Git installed on your system, open RStudio and select Global Options from the Tools menu (Tools > Global Options…). In the dialog that opens, click the Git/SVN tab on the left-hand side of the pop-up window. Near the top of the pane, there is a field for the Git executable. If it says something like “/usr/bin/git” or “C:/Program Files/Git/” then you already have Git installed. Yay! If instead it says “(Not Found)” in the Git executable field, then you will need to install Git before proceeding.
Head to the Software Carpentry instructions for Git and install whichever version is appropriate for your operating system. You only need to do this step if the previous step indicated that Git was not installed on your computer. After you install Git, shutdown and restart RStudio.
After installing Git, you’ll need to configure Git. You can do this through RStudio or in your command line interface of choice. In RStudio, open a new Terminal via Tools > Terminal > New Terminal and enter:
git config --global user.name 'Your Name' git config --global user.email 'firstname.lastname@example.org'
'Your Name' and
'email@example.com' with your actual name and e-mail (surrounded by single-quotes).
Next, if you have not already, sign up for a GitHub account. Registration is free and simple. Make sure you remember your GitHub ID and password - we’ll need those later in the lesson.
What? On some versions of Mac OS, you will need to install one more program in order to get RStudio and Git to talk with each other. If you see an error like
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun.
shut down RStudio, open the Terminal application and run
open RStudio again and you should be all set! If you want to know more about this error, head over to Stack Overflow and read about this in more detail.
At this point, you’ll want to decide how you are going to connect to GitHub. This lesson covers three options:
After you connect using one of these three options, we’ll deal with communication between RStudio and GitHub.
simulate-datain the repository name field, “A repository for simulating and plotting data” in the description field, and click the “Create repository” button. Give yourself a pat on the back: You’re using GitHub!
At this point, leave the browser open and open RStudio. We want to make a new project, using the GitHub repository we just created.
Return to RStudio and paste into the Repository URL field: