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

Basically, I have a server with a git repo 'origin'. I'm trying to have another repo auto-pull from origin every time someone pushes code to it. I've been using the hooks in origin, specifically post-receive. So far, my post receive looks something like this:

git pull origin master

But when I push to origin from another computer, I get the error:

remote: fatal: Not a git repository: '/home/<user>/<test_repo>'

However, test_repo most definitely is a git repo. I can cd into it and run 'git pull origin master' and it works fine.

Is there an easier way to do what I'm trying to do? If not, what am I doing wrong with this approach? Thanks in advance.

Edit, to clarify: The repo is a website in progress, and I'd like to have a version of it available at all times that is fully up to date.

share|improve this question
up vote 2 down vote accepted

I'm using a similar hook, but GIT_DIR must point to the .git subdirectory.

cd /home/<user>/<test_repo>
GIT_DIR=.git git pull origin master
share|improve this answer
Just to note, changing into the repository doesn't require that you set GIT_DIR--it gets this automatically be parsing parent directories. – Andrew M. Feb 7 '11 at 2:23
Have you checked that? I have tested without setting GIT_DIR and it didn't work from post-receive (git 1.7.x afair), probably because GIT_DIR is set there to the repo being pushed to. – silk Feb 7 '11 at 15:33

When you set an environment variable, its only available within that shell--so when you launch another program, such as git, the local variables won't get passed along. Lets say we have


Now lets look at the following examples

$ ./

This is because the environment variable didn't get exported to the launched program.

$ ./

In ScottZ's example, setting the environment variable when you launch the program causes it to be exported ONLY for that command.


Hope this helps!

share|improve this answer
Good point, so not only do you need to make sure you are using the .git extension if the repo is non-bare you also need to export the variable in your script. – ScottZ Feb 6 '11 at 19:19
Right; if you wanted, you could always cd into the git repository before running your pull. I.e., cd /home/<user>/<test_repo> && git pull origin master. This might be a little clearer and easier. – Andrew M. Feb 6 '11 at 22:25
You are correct, but not solving the OP question. – silk Feb 6 '11 at 22:36
Thanks! I accepted silk's question because it was more direct, but your explanations were really useful. – Dane Larsen Feb 6 '11 at 23:36
Glad it helped, Dane. :) – Andrew M. Feb 7 '11 at 2:22

Are you sure you are setting GIT_DIR properly?

I assume you are pulling from a non-bare repo in that case your GIT_DIR should be


To test this run the following on the command line:

GIT_DIR=/home/user/test_repo/.git git status
share|improve this answer

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.