-
Notifications
You must be signed in to change notification settings - Fork 336
/
install-introduce-self-git.Rmd
64 lines (41 loc) · 3.36 KB
/
install-introduce-self-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
# Introduce yourself to Git {#hello-git}
In the shell (Appendix \@ref(shell)):
``` bash
git config --global user.name "Jane Doe"
git config --global user.email "[email protected]"
git config --global --list
```
substituting your name and **the email associated with your GitHub account**.
The [usethis package](https://usethis.r-lib.org) offers an alternative approach. You can set your Git user name and email from within R:
```{r, eval = FALSE}
## install if needed (do this exactly once):
## install.packages("usethis")
library(usethis)
use_git_config(user.name = "Jane Doe", user.email = "[email protected]")
```
## More about `git config`
An easy way to get into a shell from RStudio is *Tools > Terminal* or *Tools > Shell*. More about the shell in the Appendix \@ref(shell).
Special Windows gotchas: If you are struggling on Windows, consider there are different types of shell and you might be in the wrong one. You want to be in a "Git Bash" shell, as opposed to Power Shell or the legacy `cmd.exe` command prompt. Read more in [the Appendix](#windows-shell-hell). This might also be a reason to do this configuration via the usethis package in R.
What user name should you give to Git? This does not have to be your GitHub user name, although it can be. Another good option is your actual first name and last name. If you commit from different machines, sometimes people work that info into the user name. Your commits will be labelled with this user name, so make it informative to potential collaborators and future you.
What email should you give to Git? This __must__ be the email associated with your GitHub account.
The first two commands used in the shell beginning with `git config --global` return nothing in the terminal. You can check that Git understood what you typed by looking at the output of the third from `git config --global --list`.
### Configure the Git editor {#git-editor}
Another Git option that many people eventually configure is the editor. At some point, you will fail to give Git what it wants in terms of a commit message and it will kick you into an editor. This can be distressing, if it's not your editor of choice and you don't even know how to save and quit. You can enforce your will with something along these lines:
``` bash
git config --global core.editor "emacs"
```
Substitute your preferred editor for `"emacs"` here. Software Carpentry's Git lesson has a comprehensive listing of the exact `git config` command needed for [many combinations of OS and editor](https://swcarpentry.github.io/git-novice/02-setup.html).
### Configure the default name for an initial branch
You may also want to configure the default name for the initial branch in a new repo.
Historically, this has been `master`, as that was baked into Git itself.
It's increasingly common to use `main` instead, but you have to opt-in to this.
In 2020, the `init.defaultBranch` setting was introduced so that this became user-configurable.
Shortly thereafter, major Git hosts like GitHub and GitLab made `main` the default initial branch name for repos created on their platforms and also provided considerable support for renaming existing default branches.
You can set your default initial branch name to `main` like so, in the shell:
``` bash
git config --global init.defaultBranch main
```
or from R (the default for `name` is `"main"`):
```{r eval = FALSE}
usethis::git_default_branch_configure()
```