First-Time Git Setup
Posted in how to on May 26, 2020 ‐ 2 min read
There are a few things that should be done after getting git setup so that your environment is fully configured. They’re really easy but I’m always forgetting what they are…
git config
Git comes with a tool called git config
that lets you get and set configuration variables that control all aspects of how Git looks and operates. These variables can be stored in three different places:
/etc/gitconfig file: Contains values applied to every user on the system and all their repositories. If you pass the option
--system
togit config
, it reads and writes from this file specifically.~/.gitconfig or ~/.config/git/config file: Values specific personally to you, the user. You can make Git read and write to this file specifically by passing the
--global
option, and this affects all of the repositories you work with on your system.config file in the Git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. You can force Git to read from and write to this file with the
--local
option, but that is in fact the default. (Unsurprisingly, you need to be located somewhere in a Git repository for this option to work properly.)
Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.
View Settings
You can view all of your settings and where they are coming from using:
$ git config --list --show-origin
Example output:
$ git config --list
user.name=John Doe
user.email=johndoe@example.com
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto
...
You should also use this command after making the below changes so you can verify they’re correct.
Configure Settings
Your Identity
The first thing you should do when you install Git is to set your user name and email address. This is important because every Git commit uses this information, and it’s immutably baked into the commits you start creating:
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
Git Editor on Windows
Now that your identity is set up, you can configure the default text editor that will be used when Git needs you to type in a message. If not configured, Git uses your system’s default editor. This is fine for Linux, but on Windows I like to use Notepad++.
On a Windows system, if you want to use a different text editor, you must specify the full path to its executable file. This can be different depending on how your editor is packaged.
$ git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"