B Installing Git
Git is a separate program from R and RStudio and you’ll need it installed on your computer before RStudio can do anything useful with it. This Appendix gives a slightly fuller version of the installation instructions in Section 9.4.1. Once Git is installed, head back to Chapter 9 to configure it and connect it to GitHub.
Before you install anything it’s worth checking whether you already have Git, as there’s a reasonable chance you do (especially on a Mac or Linux machine). Click on the Terminal tab in the Console window in RStudio and type git --version (the space after git matters). If you see something along the lines of git version 2.39.3 then you’re already sorted and can skip straight to the note on checking that RStudio can find it at the end of this Appendix. If instead you get an error along the lines of git: command not found then read on.
Windows. Download and run the installer for Git for Windows. There are a great many screens in this installer and you can safely accept the default on every single one of them. Amongst other things it installs a program called Git Bash, which we don’t use anywhere in this book but which does no harm sitting there.
Mac. The simplest approach is to let macOS install Git for you. Type git --version into the Terminal as described above and, if Git isn’t installed, macOS will offer to install the Xcode command line tools for you. Accept and wait for it to finish. If you’d rather use a proper installer then you can download one from git-scm.com and install it by double clicking on the downloaded package in the usual way. If you have previously installed Xcode and want a more up to date version of Git than the one it gave you, there are a few more steps documented here (and if you’ve never heard of Xcode then don’t worry about it!).
Linux. Git is very often installed already, so do check with git --version first. If it isn’t, use your OS package manager to install it from the official repository. On Debian and Ubuntu (or variants of) open your Terminal and type
sudo apt update
sudo apt install git
whereas on Fedora you would use
sudo dnf install git
You will need administrative privileges to do either of these. For other flavours of Linux see here for further installation instructions.
Checking RStudio can find Git. Whichever operating system you’re using, once the installation has finished verify that it worked by running git --version in the Terminal tab in RStudio again. On some installations (MS Windows being the usual culprit) this can still produce an error even though Git installed perfectly well, because RStudio doesn’t yet know where to look for it.
To sort this out go to Tools -> Global Options -> Git/SVN in RStudio, make sure that ‘Enable version control interface for RStudio projects’ is ticked and check that the ‘Git executable:’ path is correct for your installation. On Windows this path usually ends in git.exe and on Mac and Linux in git. If the box is empty or the path is wrong, click the Browse... button and navigate to where you installed Git. You will need to restart RStudio after doing this.