0

I have a config.php file with my configuration (for example, the MySQL credentials). Those credentials are different in my local version and in the production server (in the local MySQL, I use user root, and in the production server, the user max). I want to manage it with git. I need to push and pull every file but not the config.php. I found this command :

git update-index --assume-unchanged config.php 

but can I change the remote config.php file (for example, if I change the remote password)? And how to change the local config.php file without affecting the remote? Should I put this file to the .gitignore?

Fahim Uz Zaman
  • 444
  • 3
  • 6
m.Sarto
  • 179
  • 3
  • 16

1 Answers1

-1

You could add the file to the .gitignore file, assuming it hasn't been committed yet and in case the file is being tracked then you can follow this solution in order to remove the file from files being tracked by git and once you do that, the changes made within your local config.php file will not be tracked by git. So before you add it to the .gitignore file my recommendation would be:

  1. In case the file is already being tracked (which I am assuming is the case) then update the config.php with the remote server details and push, then set back the local details and follow these steps here to stop tracking the config.php file and add it to the .gitignore file.

NOTE The above approach assumes that you donot plan to and won't change the remote config.php details in future.

  1. Alternatively create blocks/functions within your config.php file that store the details of the local setup and remote setup then add a PHP file or probably another code block within the config.php file that checks the base_url to determine which config details to run. in this case you wouldn't need to add the config.php to the .gitignore file.
nuwe1
  • 79
  • 9
  • `.gitignore` file only prevents _new_ files from being added. As soon as a file is tracked, changes will always show up. – knittl Nov 17 '20 at 14:35
  • In that case, you can stop the tracking of the file and then add it to the `.gitignore` According to [this](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) you can be able to do that. – nuwe1 Nov 17 '20 at 15:03