Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add ignored config file to git repo as sample

Tags:

git

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.

like image 924
sleepynate Avatar asked Sep 10 '10 16:09

sleepynate


People also ask

How do I force add an ignored file in Git?

The git add command can be used to add ignored files with the -f (force) option.


2 Answers

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.

like image 76
Jonathan Leffler Avatar answered Oct 03 '22 16:10

Jonathan Leffler


You can also version and distribute:

  • a .gitattributes files declaring a filter driver (for only 'config.dist')
  • a smudge script which will detect that content and generate the final (and private, as in "non-versioned" 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

alt text

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
like image 32
VonC Avatar answered Oct 03 '22 16:10

VonC