forked from jennybc/happy-git-with-r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-git.Rmd
121 lines (73 loc) · 5.65 KB
/
install-git.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Install Git {#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. (But consider *updating* an existing installation.)
Otherwise, find installation instructions below for your operating system.
```{r setup, include = FALSE}
has_bash <- Sys.which('bash') != '' && .Platform$OS.type != 'windows'
```
## Git already installed?
Go to the shell (Appendix \@ref(shell)). Enter `which git` to request the path to your Git executable:
```{bash collapse = TRUE, eval = has_bash}
which git
```
and `git --version` to see its version:
```{bash collapse = TRUE, eval = has_bash}
git --version
```
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.
macOS users might get an immediate offer to install command line developer tools. Yes, you should accept! Click "Install" and read more below.
## Windows {#install-git-windows}
**Option 1** (*highly recommended*): Install [Git for Windows](https://git-for-windows.github.io/), also 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, but you might encounter them elsewhere and I want you to be well-informed.
We like this because Git for Windows 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 "Git Bash" shell will be useful as you venture outside of R/RStudio.
* **NOTE:** When asked about "Adjusting your PATH environment", make sure to select "Git from the command line and also from 3rd-party software". Otherwise, we believe it is good to accept the defaults.
* Note that RStudio for Windows prefers for Git to be installed below `C:/Program Files` and this appears to be the default. This implies, for example, that the Git executable on my Windows system is found at `C:/Program Files/Git/bin/git.exe`. Unless you have specific reasons to otherwise, follow this convention.
This also leaves you with a Git client, though not a very good one. So check out Git clients we recommend (chapter \@ref(git-client)).
FYI, this appears to be equivalent to what you would download from here: <https://git-scm.com/download/>.
**Option 2** (*recommended*): Install [Git for Windows](https://git-for-windows.github.io/) via the [Chocolatey](https://chocolatey.org) package manager. If this means anything to you, Chocolatey is like [`apt-get`](https://en.wikipedia.org/wiki/APT_(Debian)) or [Homebrew](https://brew.sh), but for Windows instead of Debian/Ubuntu Linux or macOS. As far as I can tell, using Chocolatey to install Git for Windows gives the same result as installing it yourself (option 1).
This obviously requires that you already have [Chocolatey](https://chocolatey.org) installed or that you are up for installing it. It is not hard and the [instructions are here](https://chocolatey.org/install). This may be worthwhile if it seems likely you will be installing more open source software in the future.
After you install Chocolatey, in a shell (Appendix \@ref(shell)), do:
``` bash
choco install git.install
```
This installs the most current [Git (Install) X.Y.Z](https://chocolatey.org/packages/git.install) Chocolatey package. At the time of writing, that is "Git (Install) 2.33.1", but that version number will increment over time.
### Updating Git for Windows
If you already have Git for Windows, but it's not the latest version, it's a good idea to update.
Since v2.16, you can [update like so from the command line](https://stackoverflow.com/a/48924212):
``` bash
git update-git-for-windows
```
## macOS
**Option 1** (*highly recommended*): Install the Xcode command line tools (**not all of Xcode**), which includes Git.
Go to the shell and enter one of these commands to elicit an offer to install developer command line tools:
``` bash
git --version
git config
```
Accept the offer! Click on "Install".
Here's another way to request this installation, more directly:
``` bash
xcode-select --install
```
We just happen to find this Git-based trigger apropos.
Note also that, after upgrading macOS, you might need to re-do the above and/or re-agree to the Xcode license agreement. We have seen this cause the RStudio Git pane to disappear on a system where it was previously working. Use commands like those above to tickle Xcode into prompting you for what it needs, then restart RStudio.
**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 the macOS installer is here: <https://github.com/timcharper/git_osx_installer>.
- At that link, you can find more info if something goes wrong or you are working on an old version of macOS.
**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](http://brew.sh), "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
```
## Linux
Install Git via your distro's package manager.
Ubuntu or Debian Linux:
```sh
sudo apt-get install git
```
Fedora or RedHat Linux:
```sh
sudo yum install git
```
A comprehensive list for various Linux and Unix package managers:
<https://git-scm.com/download/linux>