Make Github push to a remote server when it receives updates

北战南征 提交于 2019-11-30 12:36:13

As I understand github doesn't allow you to define "true" hooks. Like post-receive. Instead they provide something called a webhook to developers. what you can do with this is issue a web request to any URL specified by you whenever there's a push to your repository.

So what you can do is: setup a webserver on you remote git server and configure github to make an http call to it on post-receive. Whenever github notifies your remote server do a pull on it from github.

See here on how to use webhooks: https://help.github.com/articles/post-receive-hooks

P.S. A true hook mechianism whould have been a possible security vulnerability for github cause it allows you to execute custom code on their servers. So they have made something that does not allow you to execute anything but still allows you to do anything you want.

VonC

To illustrate Yervand's answer (upvoted), consider this peligangit as an example of a simple HTTP server (that you can install on your amazon-ec2 instance), which will:

  • start a simple HTTP server.
  • listen for a POST from a GitHub webhook
  • it will pull down the new commits

That library would fetch, and then reset the main branch on origin/master.
That is one way to do it. (see githook.py)

def hard_reset_repos(self):
    self.server.source_repo.fetch([self.server.source_repo.origin])
    self.server.source_repo.reset(['--hard', self.server.source_repo.originMaster])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!