Git Config(s)
System level
Applied to every user on the system and all their repositories.
- to view,
git config --list --system
(may need sudo) - to set,
git config --system color.ui true
- to edit system config file:
git config --edit --system
Global User level
Specific personally to you, the user.
- to view:
git config --list --global
- to set:
git config --global user.name xyz
- to edit global config file:
git config --edit --global
Stored in any one of:
~.config/git/config
~.gitconfig
Repository level
Specific to that single repository.
- to view:
git config --list --local
- to set:
git config [--local] core.ignorecase true
- to edit repository config file:
git config --edit [--local]
Set repo-specific (non-global) config settings:
git config user.name "Alex Sokolsky"
git config user.email "asokolsky@gmail.com"
git config core.sshCommand "ssh -i ~/.ssh/private_key"
Make sure your private identity is available:
ssh-add ~/.ssh/private_key
Then
git remote add origin git@github.com:asokolsky/repo.git
git push --set-upstream origin master
View All Settings
Show system, global, and (if inside a repository) local configs:
git config --list
To also show the origin file of each config item:
git config --list --show-origin
To get e.g. user.name
:
git config user.name
You may also specify options --system
, --global
, --local
to read that value at a particular level.
Best Practices - Global Config
Followed:
git config --global user.name "Alex Sokolsky"
git config --global user.email "asokolsky@gmail.com"
git config --global core.editor /usr/bin/emacs
git config --global core.excludesfile ~/.gitignore
git config --global core.pager ''
git config --global push.default current
where ~/.gitignore
:
*~
.*.swp
.DS_Store
Example ~/.gitconfig
:
# a matter of taste (uncomment if you dare)
[branch]
# sort = -committerdate
sort = committerdate
[column]
ui = auto
[commit]
verbose = true
[core]
# fsmonitor = true
# untrackedCache = true
editor = emacs
excludesfile = ~/.gitignore
[diff]
algorithm = histogram
colorMoved = true
# colorMoved = plain
mnemonicPrefix = true
renames = true
[feature]
experimental = true
[fetch]
all = true
prune = true
pruneTags = true
[grep]
patternType = perl
[help]
autocorrect = prompt
[init]
defaultBranch = main
[merge]
# just 'diff3' if git version < 2.3
conflictstyle = zdiff3
[pull]
rebase = true
[push]
default = simple
autoSetupRemote = true
followTags = true
[rebase]
autoSquash = true
autoStash = true
updateRefs = true
[rerere]
enabled = true
autoupdate = true
[tag]
sort = version:refname