Useful Systemwide Git Defaults -- Revisited
A while back, I wrote about
“useful git defaults”. This is a tricky subject, as a sufficiently aged
~/.gitconfig
is much like a vimrc
or Chief O’Brien’s rank: a very
religious topic.
Nonetheless, it’s one of those things where a few small adjustments to
the system-wide git configuration (a la /etc/gitconfig
) can make things
much, much easier — particularly in the case where there are multiple systems
to manage, and multiple people using them.
I’m pretty happy with those defaults, but a lot has changed since 2014.
git config file locations
The configuration paths available have also changed:
To do this, we can leverage the little-used system-wide git config file at
/etc/gitconfig
. Remember that by default git looks at four files to
determine its configuration (in ascending order of priority):
/etc/gitconfig
(system),~/.config/git/config
,~/.gitconfig
(user aka global), and.git/config
(configuration for the current repository).
(Technically, #2 is $XDG_CONFIG_HOME/git/config
.)
This allows us to set defaults in the system configuration file without
interfering with people who prefer different settings: their global config at
~/.gitconfig
will win.
/etc/gitconfig
For our purposes, we’re talking about settings in /etc/gitconfig
, though
they can certainly be used in other places as well.
This config sets a couple safer defaults for pushing, makes git merge/diff/rebase a little more DWIM, causes the committer, as well as the author, information to be displayed by default, as well as allowing for an easy way to override the system config on a per-system basis. (In case, say, you’re using puppet or the like to distribute this configuration across multiple hosts.)
Note that we do not do some things that individuals may wish to do, as we’re
aiming for “unobtrusive, reasonable universal defaults”, e.g.
rebase.autosquash
is not set to true
. (Though the author highly
recommends this setting.)