Version Control: Getting Started

RStudio's version control features are tied to the use of Projects (which are a way of dividing work into multiple contexts, each with their own working directory). The steps required to use version control with a project vary depending on whether the project is new or existing as well as whether it is already under version control.

Using a directory already under version control

If you have an existing directory which is already under Git or Subversion version control then you simply need to create a new RStudio project for that directory and then version control features will be automatically enabled. To do this:

  1. Execute the New Project command (from the Project menu)
  2. Choose to create a new project from an Existing Directory
  3. Select the appropriate directory and then click Create Project

A new project will be created for the directory and RStudio's version control features will then be available for that directory.

Creating a new project based on a Git or Subversion repository

If you have an existing Git or Subversion repository that you want to use as the basis for an RStudio project you should:

  1. Execute the New Project command (from the Project menu)
  2. Choose to create a new project from Version Control
  3. Choose Git or Subversion as appropriate
  4. Provide the repository URL (and other appropriate options) and then click Create Project

The remote repository will be cloned into the specified directory and RStudio's version control features will then be available for that directory.

Adding version control to a project

If you have an existing directory that you want to add version control to, you should consult the documentation for Git or Subversion concerning how to initialize a repository (both local commands as well as commands required to connect it to a remote server).

Subversion directories are always paired with an external repository, so cannot be configured for version control without also configuring the external connection. However, Git repositories can be created in purely local mode (if for example you want to track changes locally but aren't concerned with collaborating and/or syncing between multiple workstations). To add a git repository to an existing project:

  1. Execute the Project Options command (from the Project menu)
  2. Choose Version Control options
  3. Change the version control system from (None) to Git
  4. Confirm that you wish to initialize a new Git repository

A Git repository will be created for the project and you'll be prompted to restart RStudio to enable version control features for the project.

Related Topics