7 Install Git

You need Git, so you can use it at the command line and so RStudio can call it.

If there’s any chance it’s installed already, verify that, rejoice, and skip this step.

Otherwise, find installation instructions below for your operating system.

7.1 Git already installed?

Go to the shell (Appendix A). Enter which git to request the path to your Git executable:

which git
## /usr/bin/git

and git --version to see its version:

git --version
## git version 1.8.5.6

If you are successful, that’s great! You have Git already. No need to install! Move on.

If, instead, you see something more like git: command not found, keep reading.

Mac OS users might get an immediate offer to install command line developer tools. Yes, you should accept! Click “Install” and read more below.

7.2 Windows

Option 1 (recommended): Install Git for Windows, previously known as msysgit or “Git Bash”, to get Git in addition to some other useful tools, such as the Bash shell. Yes, all those names are totally confusing. You may accept all the default settings during installation.

  • This approach leaves the Git executable in a conventional location, which will help you and other programs, e.g. RStudio, find it and use it. This also supports a transition to more expert use, because the Bash shell will be useful as you venture outside of R/RStudio.
  • This also leaves you with a Git client, though not a very good one. So check out Git clients we recommend (chapter 9). *RStudio for windows likes for git to be in the Files(x86) folder. If not in this location, RStudio may not detect it, and may cause headaches for you later.

Option 2 (NOT recommended): The GitHub hosting site offers GitHub Desktop for Windows that provides Git itself, a client, and smooth integration with GitHub.

  • Their Windows set-up instructions recommend this method of Git installation.
  • Why don’t we like it? We’ve seen GitHub Desktop for Windows lead to Git installation in suboptimal locations, such as ~/AppData/Local, and in other places we could never find. If you were only going to interact with GitHub via this app, maybe that’s OK, but that does not apply to you. Therefore, we recommend option 1 instead.

7.3 Mac OS

Option 1 (highly recommended): Install the Xcode command line tools (not all of Xcode), which includes Git. If your OS is older than 10.11 El Capitan, it is possible that you must install the Xcode command line tools in order for RStudio to find and use Git.

Go to the shell and enter one of these commands to elicit an offer to install developer command line tools:

git --version
git config

Accept the offer! Click on “Install”.

Another way to request this is via xcode-select --install. We just happen to find this Git-based trigger apropos.

Option 2 (recommended): Install Git from here: http://git-scm.com/downloads.

  • This arguably sets you up the best for the future. It will certainly get you the latest version of Git of all approaches described here.
  • The GitHub home for this project is here: https://github.com/timcharper/git_osx_installer.
    • At that link, there is a list of maintained builds for various combinations of Git and Mac OS version. If you’re running 10.7 Lion and struggling, we’ve had success in September 2015 with binaries found here: https://www.wandisco.com/git/download.

Option 3 (recommended): If you anticipate getting heavily into scientific computing, you’re going to be installing and updating lots of software. You should check out homebrew, “the missing package manager for OS X”. Among many other things, it can install Git for you. Once you have Homebrew installed, do this in the shell:

brew install git

Option 4 (NOT recommended): The GitHub hosting site offers GitHub Desktop for Mac that provides the option to install Git itself, a client, and smooth integration with GitHub..

  • Their Mac set-up instructions recommend this method of Git installation.
  • We don’t like GitHub Desktop as a Git client, so this is a very cumbersome way to install Git. Consider this option a last resort.

7.4 Linux

Install Git via your distro’s package manager.

Ubuntu or Debian Linux:

sudo apt-get install git

Fedora or RedHat Linux:

sudo yum install git

A comprehensive list for various Linux and Unix package managers:

https://git-scm.com/download/linux