I have a website with a staging subdomain that automatically updates when I push from my dev machine. I am excluding 2 files from commits because they contain credentials. I am not using .gitignore because this is a temporary solution to a larger problem of where to store credentials for production. I tried using environment variables in .htaccess but they seem to be more vulnerable to leaking as mentioned in this question-
In the meantime while I figure out a permanent solution, I put the credentials back in their files and exclude them from commits. The issue is when I push commits to the server, the excluded files revert to their previous version causing me to manually add the files after every time I push.
This question's answer had this comment-
Any sort of secret should be passed in through the environment or a config file. It's fine to create a template for this purpose and check that in, then have a script to copy it into an ignored location so that you can edit it and add the secret. For most major production systems, secrets are typically passed in through the environment so they aren't written to disk.
I am struggling with exactly how to implement this on my production server. I know it belongs in it's own question but I'm including it for additional context.
How do I stop git from reverting excluded files on every push?