On Tue, Jan 26, 2010 at 08:53:06PM -0600, David Bruce wrote:
> Hi,
> A little follow-up, now that I know a bit more about git and the
> problem I'm encountering.
> Basically, on the server I have two git repos for tux4kids-web.  The
> bare repo which receives pushes is /git/tux4kids/tux4kids-web.git.
> There is an ordinary, non-bare clone of this repo on the same machine
> at /home/groups/tux4kids/tux4kids-web.  The working directory of this
> repo contains the docs for our public-facing website.  What I want is
> for this directory to be automatically updated whenever the bare repo
> receives a push.
> My understanding is that this should be done through the "post-update"
> hook under the bare repo, i.e. at
> /git/tux4kids/tux4kids-web.git/hooks/post-update.  I've edited this
> script so that it works as intended when invoked directly (it
> basically changes to the target repo, does a "reset GIT_DIR .", and a
> "git pull").

When you say "reset GIT_DIR ." what are the exact commands
you're using?  I'm not sure what that means.

Things to note about post-update hooks:

- When run via git they will define the 'GIT_DIR' environment
variable.  It is usually defined to '.', aka the current
directory, so many hooks unset that variable.

It is quite common to say "unset GIT_DIR" at the top of a
#!/bin/sh post-update shell script.

This should be all it takes...

unset GIT_DIR
cd /home/groups/tux4kids/tux4kids-web &&
git pull origin master

If you have uncommitted changes in tux4kids-web then that will
fail because 'git pull' might complain about losing your
uncommitted changes.

If the intention is to never do that (unless by accident) then
the following works by throwing away any accidental edits in

unset GIT_DIR
cd /home/groups/tux4kids/tux4kids-web &&
git fetch origin &&
git reset --hard origin/master

> However, the post-update hook never gets run when I push to the bare
> directory.  Is there something I need to do to enable
> "hooks/post-update" other than changing its name from
> "post-update.sample" to "post-update", editing it so it does what I
> want, and making sure it is executable?

That should be all it takes.  Hmm.
You already mentioned that it's chmod 755 and renamed.

You're sure it's not running?  Have you tried logging to a file?

If you 'git push' and everything's up-to-date then it probably
won't run, I would assume.

You can always force the push for testing purposes:

# Force push the previous revision to the remove master branch
git push origin +master~:master

# Now push the latest; this should update your checkout
git push origin master

Of course, don't try this from
since the hook chdirs there and does stuff.

You'll need a separate place for actually making changes,
commiting, and pushing.

More about hooks:


You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To post to this group, send email to git-us...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to