Searching for the best approach to keep my config files separate, yet not introduce extra steps for new developers setting up their environments.
I am guessing a submodule would suffice to do the job, but then how would I switch configs seamlessly depending on the task at hand, aka pull in DEV config regularly, pull PROD branch of config repo during build?
Needs to be:
Thank you in advance.
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:
config.tpl
)config.dev
, config.prod
, ...)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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With