lcdservices
lcdservices

Reputation: 863

git: ignore files in certain environments

I have my entire website maintained in a git repo. This includes an .htaccess file that has various apache directives.

Those directives are specific to my production environment. I run into an issue where some of those rules create a problem in my development environment. I want the .htaccess file maintained in the repo because the history is very important to be able to reference. But on my development space, I want to be able to modify that file so it's suitable to that environment.

Is it possible to setup a .gitignore statement that will ignore changes to this file in development, but maintain them in the production environment?

Upvotes: 1

Views: 309

Answers (1)

user229044
user229044

Reputation: 239471

No, you cannot change how Git tracks files on a per-environment basis.

There are two accepted solutions to this problem, both of which involve ignoring .htaccess:

  1. Checkin all possible versions of the file, and symlink to the correct one. Create a .htaccess.prod and a .htaccess.dev file, and then create an untracked symlink to the correct one as .htaccess. This allows you to version-control the contents of each environment's file, while still letting you deploy the working directory to production.

  2. Check in an "example" file and create an untracked copy of it in each environment. This is typically used when the config file in question contains sensitive data like credentials. Create a .htaccess.example file, and then in each environment, copy it to .htaccess and make the environment-specific modifications. You probably don't want this option, as it does not let you version-control the environment-specific changes.

Upvotes: 1

Related Questions