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:
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.
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.
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.
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:
git config --global init.defaultBranch main
or from R (the default for