Nick Williams
Nick Williams

Reputation: 23

.gitignore - keeping files on GitHub

There are many questions like this, however none seem to achieve the solution required.

How do I ignore changes to a local file without being committed to github? Example: app/etc/local.xml

Github - Has the correct local.xml this should not be overwritten! I have a local .gitignore file that contains app/etc/local.xml However when I change the file it still shows up as modified for commit.

I have tried:

git rm --cached app/etc/local.xml  

but this deletes the file from github, however it does then let me continue to edit file locally and it does not appear on a commit.

How do I keep the original file on github?

This is consistant with all files and folders in my .gitignore

Upvotes: 0

Views: 185

Answers (2)

axiac
axiac

Reputation: 72226

You are searching in the wrong direction.

The common solution for your problem is to create two files:

  • app/etc/local.xml.dist - put reasonable default values for all the settings in it and add it to the Git repository;
  • app/etc/local.xml - put the values you actually use on your computer in this file, do not add it to the Git repository (remove it if it already exists) and add its path to .gitignore.

Add a comment into local.xml.dist to teach your fellow developers they should make a copy of the file, name it local.xml and put their actual configuration values in it (and not modify local.xml.dist for this purpose).

Write the code to read local.xml.dist then, if local.xml exists load it and overwrite the values loaded from local.xml.dist. This way local.xml can contain only the values that really need to be set; if local.xml.dist already provide a default value that can be used on the local computer it can miss from local.xml.

This is how a lot of software packages work these days.

Upvotes: 2

AnoE
AnoE

Reputation: 8345

There are many questions like this because people naturaly try to do this (i.e., have config files depending on the environment in the repository) and it never works. There is no good solution for this except getting your configuration out of the repository or having one file per environment (different file/directory name) and an external symlink (or other mechanism) pointing to it. The questions you found likely have details on this.

You may think that you require the solution of git ignoring it, but that's really no use in the long term (i.e., git reset --hard will still wreck your local changes, or git merge will fail if the upstream file gets changed, incurring manual overhead all the time).

Upvotes: 1

Related Questions