Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Desynchronize' a PHP config file with Git

I'm currently working on a PHP site, and am using Git both locally (development) and on the production site (a repo on my web server uses a post-recieve hook to deploy to the web root), the details of which are outlined at toroid.org's 'Using Git to manage a web site' article.

Issue is that I also have a config.php file (of sorts) that I use for connecting to the database that differs between my local development environment (a local install of MySQL with test data) and my remote 'production' web server (which has it's own 'live' database). Whenever I push my changes to the website however the config file goes with it and replaces my 'live' config with settings connecting to the (nonexistent) development one! I then have to manually SSH to my web server and replace the config.php file, kind of defeating the purpose!

Is there any way I can get Git to... kind of 'desynchronize' the config.php file? The 'development' config.php should never get saved to the git repo, and when the production server deploys the PHP scripts etc to the web root directory, it should also leave the existing 'production' config.php file untouched.

Is there any way of doing this with Git? Thanks a million for your suggestions!

TC

like image 236
TC Fox Avatar asked Jan 01 '26 11:01

TC Fox


1 Answers

First I would remove config.php from the repository, then I would create a file named ".gitignore" and add the filename "config.php" to it.

like image 103
brain Avatar answered Jan 02 '26 23:01

brain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!