You can just leave the file changed and never commit it, but it is very annoying. And there are sophisticated methods that use multiple branches and reloads. But it is also very dirty.
The easiest solution I have found is to use a grease filter in a working environment. See the git book for more details. You can use the smudge filter to replace a specific word with something else when placing an order.
In my setup, I use this filter (you can just add this to the .git / config file on your server):
[filter "htproduction"] smudge = sed 's/\\$site-mode\\$/$site-mode:production$/' clean = sed 's/\\$site-mode.*\\$/$site-mode$/'
To activate this filter, add this line to .git / info / attributes (create this file if it does not exist):
index.php filter=htproduction
The effect of this is that all occurrences of $site-mode$ are replaced with $site-mode:production$ on your server. Now do something similar in the index.php file:
if (strpos("$site-mode$", "production") !== false)){ do_only_on_server(); }
It is highly recommended that you read smudge filters to understand what is happening and why Im not doing if ("$site-mode$" == "$site-mode:production$") (which didn't work).
Note. This answer assumes that you are using Linux on your server. This method also works with windows, but sed will probably not be available.
source share