That is called content filter driver, and it allows you to declare, in a .gitattributes
file (and only for your config files type) a smudge script which will automatically on checkout:
- combine a config file template file (
config.tpl
) - with the right config file value (
config.dev
,config.prod
, …) - in order to produced a non-versioned config file (private file)
See “Customizing Git – Git Attributes“:
echo '*.cfg.tpl filter=config' >> .gitattributes
git config --global filter.config.smudge yourScript
With that approach, you don’t need submodules, but you can generate as many config file you need depending on your environment, like for instance your branch:
A bit like in “Find Git branch name in post-update hook“, your smudge script can find out in which branch it is currently executing with:
#!/bin/sh
branch=$(git rev-parse --symbolic --abbrev-ref HEAD)