To keep all of my config files in sync I have a Github repository with all of my settings. While this works fairly well in most cases, some apps have different versions on different machines.
So now I am wondering... is there any way to set Git global config setting like this one (which causes a warning on my laptop) without causing errors on different machines with older Git versions?
One option might be wrapping the git push
command to add the flags when supported but that seems like a hack.
Create different config files for different machines and at each machine symlink one of them as the real config. The symlink itself will not be tracked, add it in .gitignore
.
The symlinking could be done in a post-checkout
hook. You need to identify the current host (e.g. uname -n
) and have a file that contains appropriate settings for the hook.
The downside of this solution is that is is not dynamic. Once a new version of Git is installed on a host, you have to check that the appropriate config works with it.
If you want something that checks whether a value is supported for an option and use another value as fallback, you’d have to parse manpages and rely on their contents. Git has nothing similar implemented. You cannot check if a value is supported, you cannot write a config file that dynamically choses the value itself.
However, it is possible to generate the config dynamically. In a similar way to how you replace an ordinary file with a symlink to chose between several static files, you can replace it with a named pipe connected to a daemon that generates the config.
In the daemon you can check git --version
and based on that choose the config options’ values. Although this is a clever solution, fully exploiting the capabilities of Unix file system, it is quite a hacky one. You have to keep the daemon running and if it stops, Git will not be able to read the config and will hang.