Skip to content

Instantly share code, notes, and snippets.

@gtallen1187
Last active February 3, 2021 19:48
Show Gist options
  • Save gtallen1187/ddf30d03645b25bffa44310a0ef50baa to your computer and use it in GitHub Desktop.
Save gtallen1187/ddf30d03645b25bffa44310a0ef50baa to your computer and use it in GitHub Desktop.
Greg's Great Guides: Global Git Config

Global Git Config

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.

Core

The commands below are essential to run when configuring your git installation.

Name

Set your name

git config --global user.name "Your Name"

Email

Set your email

git config --global user.email "[email protected]"

Store your credentials

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

Always use HTTPS protocol

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://

Fix stupid typos

Automatically correct typos

git config --global help.autocorrect 30

Fix cross-platform line ending issues

Fixes line issues caused by cross-platform development

git config --global core.autocrlf true

Use color output in terminal

Ensures that git output is provided in color in your terminal.

git config --global color.ui true

Optional

Although not required, these additional commands can be extremely helpful when configuring your git environment.

Sign your commits with your key

Replace 00000000 with your key's short ID.

git config --global user.signingkey 00000000
git config --global commit.gpgsign true

Configure your default text editor

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"

Use a global .gitignore file

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!

Use a default template for commit messages

Useful in highly structured environments and on projects with tons of contributors.

git config --global commit.template /path/to/git-commit-template.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment