Carrying your Git settings around

At work (and at home) I use SSH to administrate all computers - my mobile phone, my satellite TV receiver, desktop PCs, laptops and the various servers running at home or in the data centers.

The settings in /etc/ are kept in Git repositories so I can restore them easily when something breaks badly. It also allows me to check when I modified a file and why I did it. And it gives me the ability to merge settings from one machine onto the other one easily because all machines use the same repository, just a different branch.

When committing changes as root, the user name and email address are often not mine but root@hostname, which is misleading and gives very poor change logs when multiple admins commit changes.

The multiple admins issue is what prevents me from using

$ git config "Christian Weiske"

Environment variables

Apart from the global and repository configuration settings, Git reads the environment variables GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL. The idea now is to set them on your machine and take them via SSH on every single machine.

Local setup

At first you need to set the variables in your .bashrc file:

export GIT_AUTHOR_NAME="Christian Weiske"

Now either start a new shell or reload your current bash settings:

$ source ~/.bashrc

Local ssh configuration

Add the following line to your ~/.ssh/config file:

SendEnv LANG LC_* GIT_*

LANG and LC_* get transmitted by default, just have a look at /etc/ssh/ssh_config - we just add all the Git ones.

If you put that line at the top, before any special Host settings, it will affect all hosts.

Remote daemon setup

At least in Ubuntu 11.10 and Debian 6, sshd only accepts the LANG and LC_* variables, as seen in /etc/ssh/sshd_config:

AcceptEnv LANG LC_*

We modify the line and allow all the Git variables:

AcceptEnv LANG LC_* GIT_*

Now a quick SSH daemon reload to get it pick up the new configuration settings and we are set:

$ /etc/init.d/ssh reload
$ exit
$ ssh root@machine
Christian Weiske

I'm looking for a new job. If you can recommend a company in Leipzig/Germany that's looking for a PHP developer, please drop me a mail.

Written by Christian Weiske.

Comments? Please send an e-mail.