Keep different content of a particular file in a Git branch
configuration, deployment, git, version-control
Solution
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:
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>
This way, you'll have one single versioned configuration file and won't have to edit a single one.
Problem
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?