Connect Git to RStudio

Symbol of coding on a computer screen
Graphic showing git interacting with R

Purpose: link Git to RStudio for version control in R programming

Install Git and link to RStudio

  1. Download and install Git
  2. Link Git to RStudio via Tools | Global options:
  1. Open RStudio
  2. From the top menu, select Tools | Global Options
  3. Select Git/SVN from the left hand pane
  4. Make sure that ‘Enable version control interface for RStudio projects‘ is checked.
  5. In the ‘Git executable’ field browse to the git.exe file that you’ve installed; the likely filepath to find the git.exe file is: [local disk] C:/Program Files/Git/bin/git.exe
RStudio Global Options dialog box
Showing how to enter the filepath to the Git executable file in RStudio
Showing the filepath to the Git.exe file

Enable Git version control with an existing RStudio project

With Git installed and the git.exe file linked to RStudio (see above), you can now enable version control for individual RStudio projects.

  • Open RStudio and open your existing project (e.g. from Recent projects)
  • Select Tools | Project Options
  • Click on Git/SVN in the left hand pane, and select Git from the ‘Version control system‘ dropdown.
  • A pop-up asks you to confirm if you want to initialize a new Git repository – click Yes.
  • Then another pop-up asks you to confirm RStudio to be restarted to activate the new repository – click Yes.
  • You’ll now see in your RStudio window, that a new Git tab has appeared (next to Environment, History, Connections), and in your project directory, a new .git folder has been added.
RStudio Tools - Project Options window
RStudio window showing the Git tab has been added