Drupal give us an excellent documentation about how to setup our settings file, but what about if we are developing our site using a local environment, what shall we know? which are the best practice that we must keep in mind.
Git Ignore file
By default Drupal provides an gitignore file which allow to remove settings.php file from any tracking from Git, however something we need to handle any change on this file to a particular cases. Perhaps if we deploy our site in on Pantheon and we need to "redirect incoming request" then in order to send all our custom changes we should modify the settings file and keep tracking by git.
Force to tracking ignore file
Make any changes on settings.php after that you should add it to git tracking,
git add --force sites/default/settings
Once you added you settings file, feel free to push all changes to your repository, and deploy it until your live environment.
What about my custom local settings
Now, you want to re-define settings file based on your local environment, but whatever change on your settings file will be detected by git, it is something you need to aware, for example the database connection on your production environment will be different than your local environment.
I recommend you the following cases what I usually use and any of those work for me, it is possible you could use any one,
- Remove settings.php file from git once you deployed to your live environment. You will need to remove it from git but you should avoid remove from file system, then you need to remove it from git cache using the following command:
git rm sites/default/settings --cached
- Update git index to avoid chace any change on settings file, you could use the following command:
git update-index --assume-unchanged sites/default/settings
- Implement a local settings file like Drupal 8 started to use it, add those new lines to your local settings.php file and add a new one called: "settings.local.php", then you will be able to add your custom local settings on it, and they will overwrite any settings from you settings.php tracked on your repository. Remember you need to verify that your new local settings file will be ignore by git.
I hope, it will be very useful to your projects,
Have a ball!