Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running a local dev server on Apache. I have a script (written in PHP) that scans all of the local dev sites I have up and running, and tells me which have outstanding items to commit to git. When I run git status as my own user, git ignores the files set in my .gitignore file. But when I run the command via Apache/PHP, those files are not ignored.

I'm not sure I'm explaining that very well, so by way of a demonstration, I have a folder with three files:


My gitignore contains this line, to ignore all backup files:


When I run the git status command manually, I see this (with the backup file correctly ignored):

dave$ git status

If I run exec('cd /dir/ && git status -s /dir/', $output); from PHP, I see:


The backup file shows up as an unversioned file.

I don't want to set the gitignore on a per-repo basis. Is there any way I can get my www-data user to use a gitignore? Or is there a higher-level gitignore setting for all users on a machine?

share|improve this question

You can set a global .gitignore using the following configuration command:

git config --global core.excludesfile /path/to/.gitignore_global

Note that the filename could be whatever you want, in the example I've used .gitignore_global

share|improve this answer
Doesn't that just set it for your user, though, not all users? The global refers to all repositories, not all users and all repositories. – Dave Child Feb 22 '13 at 8:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.