Config files and dev/staging/prod

If you’re using any kind of framework in your development, you’ll most likely have database and api/route configuration files somewhere in the mix of things.  Since most frameworks come with a blank configuration file, any changes you make locally will be end up with git asking for you to merge the files on a pull from the framework origin.  Or, conversely, if you’re pushing from your development machine to staging, and from staging to prod, each of those may have a separate configuration file.  One way to avoid merging each of these on pull/push is to set up a .gitattributes file for merging strategies on each of the servers.

For instance.  I want to keep the locally modified version of the config file, and I don’t want to explicitly merge it each time I pull from origin, so in my .gitattributes file I put the following:

/system/cfg/config.php merge=ours

Then, when I pull, git will automatically merge the framework, but ignore my config.php file – or, rather, keep mine instead of the one I pulled in.

If you do this for each necessary config file on each server, then when you push to say production, the production config file will remain, and you won’t accidentally push the configuration settings for your development server onto production.  A good way to push to various deployments is to use hooks.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.