Herr Bischoff

How to Efficiently Track Server Config Files With Git

If you like to mess around with servers by hand, like I do, tracking configurations across machines is crucial. You make some changes on one of them and want to see that change reflected elsewhere without copy-and-pasting. You could go the way of leveraging automation tools — or simply use Git and get revision tracking out of the box.

Below is an example for a FreeBSD machine.

cd /usr/local/etc
git init
git config --local status.showUntrackedFiles no
git commit --allow-empty -m "Initial commit"
git add newsyslog.conf.d
git commit -m "Add newsyslog configurations"

The main trick is the local status.showUntrackedFiles setting that avoids recursively checking for untracked files, cluttering the status output and doing unnecessary work.

To avoid any collisions, you could also use a bare repository and an alias. Below is the example adjusted for the root directory.

git init --bare /.cfg
alias cfg="git --git-dir=/.cfg/ --work-tree=/"
cfg config --local status.showUntrackedFiles no
cfg commit --allow-empty -m "Initial commit"
cfg add /usr/local/etc/newsyslog.conf.d
cfg commit -m "Add newsyslog configurations"

If you like that approach, make sure the alias is in your root shell configuration.