Automatically pulling on remote server with Git push? Automatically pulling on remote server with Git push? php php

Automatically pulling on remote server with Git push?


If it is easy to run script to push, you could setup hooks to push:

  • from GitHub to a bare (empty worktree) repo on your web server
  • from your bare repo on your web server to your "live" repo (with a worktree representing your web site)

You can then associate that with a hook on your "live" repo to update itself (through a "git merge", merging the content of your bare repo to your "live" repo), whenever your bare repo push anything.

You get the effect you want: any push to your GitHub repo (for a certain branch I suppose) will trigger a refresh on your "live" web server repo.


I've made something that works almost exactly this way, except that the "remote" repo that receives the push is on the same machine as the repo that afterward pulls. It is true (and important) that exactly the same set of users have permissions on both repositories. (But this should be OK; you don't want random people pushing your repo.) In any case I simply have the git post-update hook call a shell script that does the pull for me. The one tricky bit is that you have to clean the environment (I used env -i, or you can unset git-related variables), otherwise the pull gets confused.


Here is a WebHook that maybe could help you. I think it does exactly what you're looking for: Remote Server WebHook