Calling 'git pull' from a git post-update hook
I have a central git repo set up using gitolite.
I want to set up a hook such that whenever a user pushes to the repo, it performs a pull elsewhere followed by some automated testing.
So far, I only want to it perform the pull.
In the hooks directory I created the following script names post-update:
#!/bin/sh cd /home/git/www/epicac git pull
When I invoke this script using ./post-update, it does exactly what I want.
However, whenever it’s invoked automatically as I hook, I get: fatal: Not a git repository: ‘.’
Any idea why this might be happening?
4 Solutions collect form web for “Calling 'git pull' from a git post-update hook”
You have various diagnostics to run as suggested in this SO answer.
In particular, check out the the value of
While the hook is running,
GIT_DIRand (if the worktree can’t be inferred from
That means your pull won’t run with the repository in the directory you changed to.
See also blog post Using Git Inside a Git Hook:
Eventually we got our linux guru over and he noticed that the environment under which the git user runs is totally different when inside a hook.
Gitolite does a bunch of things to the env, but the one that was screwing us up was the setting of the
After we figured that out, the solution was as easy as:
in our ruby script that is triggered by the ‘
Same deal in
Git Tip: Auto update working tree via post-receive hook, but with an elegant way out of this:
It turns out the
post-receivehook starts out with the
GIT_DIRenvironment variable set to the
repo/.gitfolder, so no matter what path you ‘cd’ into it will always try to run any following git commands there.
Fixing this is simply a matter of unsetting the
(thanks to Ulrich Petri for the elegant
#!/bin/sh cd .. env -i git reset --hard
How about specifying the
#!/bin/sh cd /home/git/www/epicac git --git-dir=.git pull
This should do the trick in just one line:
git -C /home/git/www/epicac pull