Git Post-Receive Hook for Website Staging

The answer to your question is here: http://toroid.org/ams/git-website-howto

In short, what you want to do is add a “detached work tree” to the bare repository. Normally you think of your work tree as containing the .git directory. Bare repositories do not have a work tree by definition, but you can create one as long as it’s in a different directory than the bare repo.

The post-receive hook is just a simple git checkout -f to replicate the repository’s HEAD into the work directory. Apache uses that as its document root, and you’re all set. Any time you push to the bare repository, Apache will immediately start serving it.

I generally use this to automatically push to a staging server to see if the “real” environment will puke on my changes. Deploying to the live server is a completely different story. 🙂

Leave a Comment