10

I used this guide to use git to autopublish my changes on my website when I push to my remote origin git repository:

http://www.lwp.ca/james/2010/03/using-git-to-manage-online-website-projects/

Here's my /hooks/post-update file:

cd ../../public_html/dir/wbg
env -i git pull

Here's my directory structure:

/home/git/wbg.git <-- my remote git repository

/home/public_html/dir/wbg <-- my web folder

When I run

git push origin master

The repository updates but my web folder is still empty. Any ideas?

Edit: if any future traffic sees this, my real problem was that BOTH your remote origin AND your destination website directory must be git repositories. You can't just set it up to copy your project to a new folder unless that folder is also a git repo.

2
  • did you also do the chmod +x as suggested in the article?
    – eckes
    Feb 8, 2011 at 21:09
  • the link provided in this question is dead Jan 7, 2014 at 4:45

3 Answers 3

13

You can find a better alternative at http://toroid.org/ams/git-website-howto that only uses one git repository, and allows all metadata and previous history to remain outside of the DocumentRoot.

The guide you used and the one I linked referrer to another article both are based on, but the one I linked seems to be the preferred one to direct new users to in the #git IRC channel.

0
7

Not a lot to go off of here, but I can report that I successfully use a similar method to this.

For my purposes, I call my bare server repository the "Hub" and my web-facing repository the "Prime". Make sure that you have properly initialized a git repository in your server htdocs directory (Prime) and have either pushed the changes to the bare repository (Hub) or pulled them in.

This is the post-update hook I use, which is in my Hub repository's hooks directory:

#!/bin/sh

echo
echo "*** Pulling changes into Prime"
echo

cd /path/to/htdocs/ || exit
unset GIT_DIR
git pull hub master

exec git-update-server-info

Make sure this is executable! If in doubt, just edit the post-update.sample file and remove the .sample extension when done. The echoed text gives nice feedback that the copying is actually taking place. If you don't see that text, then it's not pulling the changes. And if you're not going to call your remote repository "hub", replace it with "origin" or whatever you decide to use.

As a precaution so that my Prime and local repositories don't get too out of whack, I have this as my Prime post-commit hook:

#!/bin/sh

echo
echo "*** Pushing changes to Hub"
echo

git push hub

Then I can just pull the changes from Hub into my local repository.

3
  • I tried it and I got this error: remote: remote: *** Pulling changes into Prime remote: remote: fatal: Not a git repository (or any of the parent directories): .git remote: fatal: Not a git repository (or any of the parent directories): .git
    – Citizen
    Feb 10, 2011 at 21:59
  • Ok, I solved that one. It appears that your website directory must be a git repository as well. I did that but now I get the error: remote: fatal: 'origin' does not appear to be a git repository remote: fatal: The remote end hung up unexpectedly
    – Citizen
    Feb 10, 2011 at 22:10
  • Isn't unset GIT_DIR going to cause my origin to not be able to update?
    – Citizen
    Feb 10, 2011 at 22:11
1

You might start by getting post-update to echo some debugging output. Both standard output and standard error output are forwarded to git send-pack on the other end, so you can simply echo messages and you will see these on the client that you did git push. I assume you followed the guide to the word, made the post-update script executable, cloned the repo to the web folder etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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