I have a config.php which suppose to be different in content in different branches, e.g. testing and master.
I have asked in another question (Prevent merging a file from master with Git) that how to prevent this file from merging.
But I am wondering, is this the correct way to do so?
I believe this is quite a common use case to have different config files in different environments and you want the config to keep tracked, right?
The classic way to do this is to have a default config file called config.yml-dist (let’s pretend that your original file is called config.yml) ; you add the original file in .gitignore, and version only the dist one.
After you deploy your app or re-clone the project, simply
cp config.yml-dist config.yml, and change the settings you want.This method is used by many people I met in the PHP industry.
But, there’s one I like much more and that I find cleaner: using environment variables.
Example:
This way, you’ll have one single versioned configuration file and won’t have to edit a single one.