Git all the things!

/

It is a small tip, but what that has served me well for awhile: .git all the things! Although it is seen as a "Source Code Management" tool it is really part of the Software Configuration Management toolset, in reality it is a text file state tracker. Very useful for source code, but also invaluable for configuration file.

Git repositories are lightweight and local. If you instantiate one in a directory it lives in ./.git, unobtrusively. Among the first things I do when setting up a new box/image is to set up local .git repositories in useful areas of configuration modification. For example, in my local Nginx configuration directory. Immediately after installing Nginx I do a quick

git init
git add .
git commit -m "initial installation state"

Afterwards when modifying any of my Nginx files I make a note of the change and commit it. This is so very helpful later on if something starts going wrong I can revert, or at least review my changes over time.

You can do this in other configuration areas but it is a little trickier. If you were going to manage your php.ini / my.cnf files for instance they may be mingled in with a whole pile of files you don't want to track. In this case you can make use of the .gitignore file. You would create your .gitignore file and place it in the directory with these configuration files (/etc/ or some such). But you would want to make the file restrictive by default by including the '*' wildcard at the start. This instructs git to ignore all files. Only following this do you add exceptions (prefixed with '!') for the files you wish to track:

## Ignore Everything
*

## Except these
!my.cnf
!php.ini

This way you will not start accidentally adding files if something else is installed later.

Small tip, but the practice has saved me a few headaches!