I have a git project that I’m working on locally. It’s a PHP project with a config file that stores MySQL database connection information. My local MySQL settings are different from the remote settings.
On my remote, I have a post-receive hook that will checkout the files to a folder on the server:
#!/bin/sh
GIT_WORK_TREE="../demo" git checkout -f
chmod +x hooks/post-receive
How can I tell this checkout not to include (overwrite the config file), since it will replace the remote config file with my local one? I’ve tried adding my local config file to the .gitignore, but that didn’t seem to do it.
Any idea how to exclude the config file from the checkout?
The proper solution is not committing your
config.php(or whatever its name is) at all but rather putting it in the.gitignoreand committingconfig.php.exampleinstead.So, simply remove the config file from the repository, rename it on your remote machine, pull so you have the newest commit (which would remove the file) and then move it back.