Part III · Shell and commands
30.5 Configuring git
alsogit configgitconfig.gitconfiggit aliasgit aliasesuser.emailuser.namecredential helperincludeif.gitignoregitignoreautocrlf
TL;DR
- Three levels: system (
/etc/gitconfig), yours (~/.gitconfig) and the repository's (.git/config). The closest one wins. - Set your name and email once; commits carry them forever.
.gitignorelists files git should never track: build output, secrets, editor files.
git config --global user.name "Alice Example"
git config --global user.email alice@example.com
git config --list --show-origin # every setting, and its file
On your machine
$ atfq 30.5 Files /etc/gitconfig, ~/.gitconfig Identity name and email set Settings init.defaultbranch = main pull.rebase = true core.autocrlf = input credential.helper = store (passwords in plain text in ~/.git-credentials) Aliases st, lg Includes 1 more file, read under conditions (include, includeIf)
An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.
Pitfalls
- A work and a personal email:
[includeIf "gitdir:~/work/"]loads a second file for repositories under~/work/. .gitignoredoesn't affect files already committed:⚠ git rm --cached FILEstops tracking one, keeping it on disk.credential.helper = storekeeps tokens in plain text; use your desktop keyring (libsecret) or SSH keys instead.- On Linux,
core.autocrlfshould beinputor unset;trueis for Windows.
Deep dive 2 questions
Which settings are worth setting?
init.defaultBranch (the first branch's name), pull.rebase (how pull
integrates), push.autoSetupRemote, merge.conflictstyle = zdiff3,
rebase.autoStash (stash and restore around a rebase) and fetch.prune
(forget branches deleted on the remote). Aliases (git config --global alias.st "status -sb") shorten what you type daily.
Where do personal ignores go?
Files only you produce, like your editor's, belong in
~/.config/git/ignore, read for every repository. The project's
.gitignore is for what every contributor generates.