I\'m still new to all things git and was wondering what is best practice in regards to config files. My local development server needs different config values to my live one
Various options are available:
Add a file default.conf to your Git repository.
Your app first looks for app.conf but if that does not exist, it uses default.conf.
Users who want the non-default config can copy default.conf to app.conf and then edit it.
Users should not commit app.conf into the repository, because different users may want different settings in that file. (So you should put app.conf into your .gitignore.)
Your app always loads default.conf but if app.conf is present then it will copy settings from app.conf over the settings from default.conf.
This twist has a couple of advantages:
app.conf only needs to hold the differences from the defaults, making it smaller and easier to maintain.
When the app changes, new defaults added to default.conf will be available to the app, without the user having to copy them into app.conf.
This solution is pretty similar to Alan W. Smith's answer above, with a small difference: If the app can start without the
app.conffile being present, then it will run out of the box. However, it does add some complexity to the app's startup code.The suggestion was one of a few made by Linus Torvalds on a git or kernel mailing list, but I have not been able to find it today.
You can use an environment variable to point your app at a specific config file. You might start your app like this:
CONFIG_FILE=test.conf ./start-app
or alternatively:
./start-app --config=test.conf
This means you can have multiple config files development.conf, staging.conf and production.conf. When you start the app you tell it which config file to use.
Developers who want to experiment with a different config can point at their own file, e.g. custom.conf.
You can also use environment variables or command line arguments to override specific settings:
./start-app --config=default.conf --db-url=... --debug-level=5
You can keep your default config in your master branch.
Fork off different branches for each of your different environments.
Each branch can modify the default config file as needed.
When your master branch updates, merge from master into your specific branches.
Personally, I don't recommend this approach. I think it's harder to maintain.