I have an repository for an app that I'm working on that includes a configuration file. Currently, I distribute with a .dist
extension, and have the user rename the file before editing it.
nate:~/myAwesomeApp% git ls-files
.gitignore
README
config.dist
glorious_support_lib.p
bestProgramEvar.f90
This is fine and dandy, and the actual config is ignored.
nate:~/myAwesomeApp% cat .gitignore
config
It would be sweet, however, if I could just distribute that config file under its real name and ready-to-edit, while leaving it ignored so that a newly cloned copy of the repository has a "functional" distribution, and it is not overwritten, clobbered, or otherwise molested, and such that users don't have to worry about pushing or publishing their super-secret configuration details to the interwebs via an unintended git commit -a -m 'hurrrr derp! oopsies!' && git push
Is there a way of doing this? Of having git keep around a single original version of the file that gets cloned out, but is thereafter ignored?
I'm sure this has been asked before, but for the life of me, my google-fu has failed. Lay the schoolin' on deep, SO.
The git add command can be used to add ignored files with the -f (force) option.
I'd probably include an 'install' script of some sort that copied 'config.dist' to 'config'.
I don't think there's a way to have a file both not-ignored and ignored.
You can also version and distribute:
.gitattributes
files declaring a filter driver (for only 'config.dist')config
file)Now that is bending a bit what a filter driver is about (it is about modifying the content of a file, regardless of its "state", i.e its full path and name). But it can work.
The .gitattributes
would contain:
config.dist filter=generateConfig
And you can register your smudge script (applied during the checkout step when creating/updating the working directory) like:
git config --global filter.generateConfig.smudge /path/to/generateConfig
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