When setting up git for the first time on your computer, you'll need to configure it before you can really use it. This guide below outlines some of the well-known and lesser-known configuration options that I've found to be super helpful in the past.
The commands below are essential to run when configuring your git installation.
Set your name
git config --global user.name "Your Name"
Set your email
git config --global user.email "[email protected]"
This command stores your credentials so that you don't need to type them in every time you clone a repo or push code to GitHub.
People who are super strict about security will likely say that it's bad practice to have your GitHub credentials stored in a local file on your computer, but considering I save passwords to things in sticky notes from time to time, I obviously am not concerned with implementing the highest possible levels of security in everything I do.
git config --global credential.helper store
This ensures that every time you clone a repo, you use the https:
protocol and not the git:
protocol. For most people in most environments, this won't matter. If you're working in an enterprise environment where requests outside of a firewall can only use a certain protocol to access certain destinations, this will be helpful.
git config --global url."https://".insteadOf git://
Automatically correct typos
git config --global help.autocorrect 30
Fixes line issues caused by cross-platform development
git config --global core.autocrlf true
Ensures that git output is provided in color in your terminal.
git config --global color.ui true
Although not required, these additional commands can be extremely helpful when configuring your git
environment.
Replace 00000000
with your key's short ID.
git config --global user.signingkey 00000000
git config --global commit.gpgsign true
Git uses GNU nano by default (very similar to Vim). If you'd prefer to use your favorite editor for things like commit messages, merge conflict resolutions, etc, simply run one of the commands below.
git config --global core.editor "atom --wait"
git config --global core.editor "subl -n -w"
git config --global core.editor "code --wait"
Notepad++ (Windows Only)
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
This will configure git to reference a single .gitignore
file for all git projects on your machine. Super helpful, as it eliminates the need to set up a new one for each project.
git config --global core.excludesfile ~/.gitignore_global
Here is my
.gitignore_global
in case you want to use it too!
Useful in highly structured environments and on projects with tons of contributors.
git config --global commit.template /path/to/git-commit-template.txt