devutils/ATFQ/book ATFQ git

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.
  • .gitignore lists 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

alice@laptopexample
$ 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

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.

Commands
git
Paths
~/.gitconfig ~/.config/git/config /etc/gitconfig .git/config
See also
30.4 Remotes: fetch, pull and push
27.1 Where environment variables come from