Using Git with RStudio

Git allows groups of people to work on the same documents (often code) at the same time, and without stepping on each other's toes. It's a distributed version control system.

(cribbed from tryGit)

Intro to practical version control for scientists

These slides are courtesy of Bernhard Konrad.

Installation and configuration of git

If you've already installed and configured git, skip ahead to Learn to use git with RStudio.

Install git

Mac OS 10.9 Mavericks comes with git installed. To check that git is installed, open a Terminal and run…

which git
git --version

These commands should display something similar to this:

➜  which git
➜  git --version
git version 1.9.3

For all other operating systems, go to the Git downloads web site, and click on the appropriate icon for your operating system.

If on a Mac the official Git package gives you any trouble, use the following instructions to install Git using Homebrew.

Install git using Homebrew

Homebrew is the missing package manager for Mac OS X. To install Homebrew and use brew to install Git, run…

ruby -e "$(curl -fsSL"
brew install git

Test that git is installed and working by running…

which git
git --version

Configure git

Git associates your name and e-mail address with each commit, which helps when multiple people collaborate on a project. To configure your name and e-mail address in git, open the Terminal and run…

git config --global 'Your Name'
git config --global ''

On a Mac, configure git to remember your password.

git config --global credential.helper osxkeychain

For more help configuring git, see…

Configure RStudio to use git

Learn to use git with RStudio

Create a new project

Or if you prefer, see below for instructions to open an existing project.

Open an existing project

If you already have a tab labeled Git next to the tabs Environment and History, skip these instructions.

Create and commit a file

Knit the HTML report

Change the plot

Make a change and revert it

Delete a file

Inspect your work

Use the git command line

There are many graphical interfaces for git—RStudio is one—but there is only one git command line interface, which is the common engine being used behind the scenes. If your graphical interface ever lets you down, it's useful to peak under the hood.

Learn more about the git command line

Go to tryGit and learn more about the git command line!