Chapter 7 Introduce yourself to Git
In the shell (Appendix A):
git config --global user.name 'Jane Doe' git config --global user.email 'firstname.lastname@example.org' git config --global --list
substituting your name and the email associated with your GitHub account.
The usethis package offers an alternative approach. You can set your Git user name and email from within R:
## install if needed (do this exactly once): ## install.packages("usethis") library(usethis) use_git_config(user.name = "Jane Doe", user.email = "email@example.com")
7.1 More about
An easy way to get into a shell from RStudio is Tools > Terminal or Tools > Shell. More about the shell in the Appendix A.
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. 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.
These commands return nothing. You can check that Git understood what you typed by looking at the output of
git config --global --list.
7.1.1 Configure the 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:
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.