如何正确使用Git。 使用带有DEVELOPMENT,TESTING和PRODUCTION服务器的CodeIgniter

Basically, I have a file index.php which should be different in each server. The file indicates which server it is on.

It has something like this:

On the DEVELOPMENT environment:

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

On the TESTING environment:

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'testing');

On the PRODUCTION environment:

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'production');

What's the proper way to maintain these files on each server without Git touching it?

I've added the file to .gitignore now, and I've untracked it using git rm --cached index.php then git push origin master for TESTING server and stable for PRODUCTION server.

fyi,

if you use apache you don't really have to change the index.php file because you can use your htaccess file to define your environment

for example :

SetEnvIf Host yourdevdomain$ CI_ENV=development
SetEnvIf Host yourtestdomain$ CI_ENV=testing
SetEnvIf Host example.com$ CI_ENV=production

In this case, you can set your needed Environments in your htaccess file, and you don't have to worry about overwriting some stuff with different files from different environments.

i think there is an option on nginx too

Take a look here

You can get more information from the official CI Documentation here.

With Apache you can set CI_ENV like @sintakonte's answer. With nginx and php-fpm you can set CI_ENV like this:

location ~ \.php {
    ....
    fastcgi_param CI_ENV production;
}

And leave the index.php file as default.

Cheers.