Take the 2-minute tour ×

I'm new to git so I apologize (and please correct me) if I misuse terminology here, but I'll do my best.

I'm trying to set up a bare git repo (hub) and a development site working copy (prime) on a web server. I've tried to pattern it after this article. I want the development working copy to be updated whenever the hub repo is pushed to. I'm under the impression that the proper hook for this is post-update, which I have created like so:

cd /path/to/working-copy/
RET=`git pull`
echo $RET


When I push changes from my local repo to the bare hub I get the following output from the post-update script:

remote: sites
remote: fatal: Not a git repository: '.'

However if I SSH into the server as user 'sites' and execute this script manually it works great Any ideas as to what might be going wrong with this hook or script?

share|improve this question
add comment

3 Answers

up vote 84 down vote accepted

Here is the script that ultimately worked. I think the bit I was originally missing that prevented it from working remotely was the unset GIT_DIR

cd /path/to/working-copy/ || exit
unset GIT_DIR
git pull repo branch

exec git-update-server-info
share|improve this answer
I can confirm, unsetting GIT_DIR fixes the problem. –  jmtd May 20 '11 at 16:21
Seconded. Only unsetting GIT_DIR works. –  recluze Mar 17 '12 at 5:46
For those willing the understand why: it's because git uses the variable GIT_DIR instead of PWD. cd-ing changes the PWD not the GIT_DIR. There must be a fallback in git from GIT_DIR to PWD should the first not be available. –  zupa Jun 21 '13 at 13:50
The question is why must git see it necessary to do this for the hook script (set GIT_DIR so that even the script has 'cd' elsewhere 'git whatever' will still work)? I personally would opt that git does not do this kind of magic. –  Steven Haryanto Jul 6 '13 at 5:08
The reason behind this is that Git is applying some environment variables to all core git commands. –  Casey Sep 12 '13 at 7:31
add comment

Try instead:

cd /path/to/working-copy/
env -i git pull
share|improve this answer
This feels much cleaner to me, thank you. –  Leng Nov 22 '13 at 1:01
add comment

You probably have a permissions issue. I'm not sure how you have setup your bare git repo, but if it's running under the git user, make sure that git user is allowed to perform the git pull in your project directory.

Optionally try this to find out what user you are when the hook is run:

echo `whoami`
share|improve this answer
if I ssh into the server as the git user I am able to use git pull in my project directory with no problems. I believe that is the user that should be executing the script. I can try adding the whoami line to the script, but where does the output from that script go when it is executed as a hook? Maybe I need to send that output to a log file instead of echoing? –  Ty W Oct 28 '10 at 14:11
What does echo `whoami` do that whoami does not? –  Christoffer Hammarström Oct 28 '10 at 14:21
Output to stdout from a hook script is visible to the remote doing the action. Or, in other words, if you say 'git push', output from a hook on the remote will show up in your stdout. –  ebneter Oct 28 '10 at 20:29
yeah, noticed that as I was playing with stuff. very convenient :) –  Ty W Oct 28 '10 at 21:40
add comment

Your Answer


