使用Git推动自动拉动远程服务器? [英] Automatically pulling on remote server with Git push?

查看:114
本文介绍了使用Git推动自动拉动远程服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我想要做的:



我有一个GitHub存储库,其中一部分我想让Web可见。现在我已经在自己的服务器上克隆了存储库,并且它运行良好,但为了保持最新状态,我必须手动登录并取得最新的更改。



我不确定这是否是最好的想法(或最好的方法),但是我希望远程服务器在有人推送到存储库时自动进行提取。当有人推送时,GitHub可以很容易地运行脚本,但是我不确定如何一旦有人执行该操作就不知道该如何解决。



我使用PHP来简化操作,但只是做> git pull 之类的东西自然不会因为权限而起作用。这是一个坏主意,还是有另一种实现我想要做的事情的方式?这似乎是一个常见的设置,但我不确定。



谢谢。

解决方案

如果脚本很容易运行到 push ,您可以设置钩子来推送:


    从您的Web服务器上的裸回购软件到您的实时回购软件(使用代表您的Web站点的工作树)将
  • 从GitHub复制到您的Web服务器上的裸露(空工作树)回购




然后,您可以将其与实时回购钩挂钩以更新自身(通过git合并,合并您的裸回购的内容,您的活回购),每当你裸露的回购推动任何东西。



你得到你想要的效果:任何推到你的GitHub回购对于某个分支我想)会在你的实时网络服务器回购中触发刷新。

Here's what I'm trying to do:

I have a GitHub repository, a portion of which I'd like to make web viewable. Right now I've cloned the repository on my own server and it works well, but in order to keep it up to date, I have to manually login and pull the latest changes.

I'm not sure if this is the best idea (or the best approach), but I'd like the remote server to automatically pull whenever someone pushes to repository. GitHub makes it easy enough to run a script when someone pushes, but I'm not sure how to pull once someone does that.

I was using PHP for simplicity, but just doing something like git pull naturally doesn't work because of permissions. Is this a bad idea or is there another way of achieving what I want to do? This seems like a common set up, but I wasn't sure.

Thanks.

解决方案

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.

这篇关于使用Git推动自动拉动远程服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆