"Bare" git repository: how can I let Apache always "see" the latest commit?
We've got a "bare" git repository on a server, for a Web portal project. Several programmers, designers, etc... perform dozens of push
and pull
from/to it.
Now we want to test the project on the server itself, and always test the last commit through an Apache web server which is installed on the same machine the "bare" git repository is stored in.
How can we 'unbare' the repository, and let the working directory contain always and only the last commit deriving from the last push
?
Or anything else aimin开发者_StackOverflowg to achieve the same result?
You can use a post-receive hook to do a git pull
inside your webserver
document root/repository.
in your bare repository do
mv hooks/post-receive.sample hooks/post-receive
chmod +x .git/hooks/post-receive
the post receive should be something like
#!/bin/sh
WEB_ROOT='/var/www/project'
cd $WEB_ROOT
git pull
A more elegant solution that doesn't involve that the web server area being a git repository, you can also review the git documentation about hooks
Note: if you use the simple solution, please make sure that your webserver doesn't serve the .git directory, this would give some hackers/crackers the access to the website source code!
精彩评论