Skip to the content.

Git Configuration

Scope

git config --system <name> [<value>]
git config --global <name> [<value>]
git config --local <name> [<value>]
git config --worktree <name> [<value>]
git config --file <config-file> <name> [<value>]

Show Current Configuration

git config --list  # all configs

git config <name>  # specified config

User Info

git config --global user.name 'Your Name'
git config --global user.email your@email.com  # Your working email, just as GitHub registered email

Editor: core.editor

By default, Git uses whatever you’ve set as your default text editor via one of the shell environment variables VISUAL or EDITOR, or else falls back to the vi editor to create and edit your commit and tag messages. To change that default to something else, you can use the core.editor setting.

Command Line or Terminal

Use Vim:

git config --global core.editor vim

Use Emacs:

git config --global core.editor emacs

GUI

Use gVim:

git config --global core.editor "gvim --nofork"

Use VS Code:

git config --global core.editor "code --wait"

Pager core.pager

Determine which pager is used when Git pages output such as git log and git diff.

Use less, by default.

git config --global core.pager less

Use more:

git config --global core.pager more

You can turn it off by setting it to a blank string:

git config --global core.pager ''

If you run that, Git will page the entire output of all commands, no matter how long they are.

External Diff Tools

Command Line or Terminal: diff.tool

Controls which diff tool is used by git difftool.

Generally Vim is installed on Linux and Macos by default, so vimdiff (same as vim -d) could be used:

git config --global diff.tool vimdiff

gVim (gvimdiff, same as gvim -d --nofork) could be used on Linux:

git config --global diff.tool gvimdiff
git config --global difftool.prompt false

WinMerge could be used on Windows:

git config --global diff.tool winmerge

VS Code could be used on any of Macos, Linux, and Windows:

git config --global diff.tool "vscode"
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'

GUI diff.guitool

Controls which diff tool is used by git difftool --gui or git difftool -g.

gVim (gvimdiff, same as gvim -d --nofork) could be used on Linux:

git config --global diff.guitool gvimdiff
git config --global guitool.prompt false

WinMerge could be used on Windows:

git config --global diff.guitool winmerge

Color: color.*

Use variable color.ui to determine the default value for variables such as color.status, color.diff, color.transport, color.remote, color.showBranch, and color.grep that control the use of color per command family.

Line Endings Issues

# Local Windows: Checkout Windows-style, commit Unix-style line endings
git config --global core.autocrlf true

# Local Linux/macOS/UNIX: Checkout as-is, commit Unix-style line endings
git config --global core.autocrlf input

# Both Windows
# Checkout as-is, commit as-is
git config core.autocrlf false

git config core.safecrlf true
git config core.eol native

More details about Git Handling Line Endings (CRLF).

Whitespace Error: core.whitespace / apply.whitespace

A comma separated list of common whitespace problems to notice. (See Git whitespace errors)

git diff will use color.diff.whitespace to highlight them, and git apply --whitespace=error will consider them as errors. You can prefix - to disable any of them (e.g. -trailing-space):

For example, if you want all but space-before-tab to be set, you can do this:

git config --global core.whitespace \
    trailing-space,-space-before-tab,indent-with-non-tab,tab-in-indent,cr-at-eol

Or you can specify the customizing part only:

git config --global core.whitespace \
    -space-before-tab,indent-with-non-tab,tab-in-indent,cr-at-eol

Push Default Action

git config --global push.default simple

Example

sudo git config --system color.ui true
sudo git config --system core.eol native
sudo git config --system core.safecrlf true
sudo git config --system core.filemode true
sudo git config --system core.editor vim
sudo git config --system diff.tool vimdiff
sudo git config --system help.autocorrect 1
sudo git config --system gui.encoding utf-8
sudo git config --system credential.helper store

sudo git lfs install --system

git config --global user.name 'Your Name'
git config --global user.email your@email.com
git config --global init.defaultBranch main
git config --global core.autocrlf input
git config --global core.safecrlf true
git config --global core.filemode true
git config --global core.editor "code --wait"
git config --global core.whitespace "trailing-space,space-before-tab,-indent-with-non-tab,-tab-in-indent,cr-at-eol"
git config --global diff.tool "vscode"
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
git config --global apply.whitespace fix
git config --global credential.helper osxkeychain
git config --global pull.rebase true
git config --global push.default simple
git config --global push.autoSetupRemote true
git config --global push.default simple
git config --global merge.autoStash true

References