使用 Git Push 自动拉取远程服务器?
这就是我想要做的:
我有一个 GitHub 存储库,我想让其中的一部分在网络上可见。现在,我已经在自己的服务器上克隆了存储库,并且运行良好,但为了保持最新状态,我必须手动登录并提取最新更改。
我不确定这是否是最好的想法(或最好的方法),但我希望远程服务器在有人推送到存储库时自动拉取。 GitHub 使得在有人推送时运行脚本变得很容易,但我不知道一旦有人这样做了如何拉取。
为了简单起见,我使用 PHP,但由于权限的原因,仅仅执行诸如 git pull 之类的操作自然是行不通的。这是一个坏主意还是有其他方法可以实现我想做的事情?这似乎是一个常见的设置,但我不确定。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果很容易运行脚本来推送,您可以设置挂钩来推送:
然后您可以将其与“实时”存储库上的钩子关联起来以更新自身(通过“git merge”,将裸存储库的内容合并到“实时”存储库) ,每当你的裸仓库推送任何内容时。
你得到了你想要的效果:任何对你的 GitHub 存储库的推送(我想是针对某个分支)都会触发你的“实时”Web 服务器存储库的刷新。
If it is easy to run script to push, you could setup hooks to push:
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 post-update 挂钩调用一个 shell 脚本来为我拉取。一个棘手的问题是你必须清理环境(我使用了 env -i,或者你可以取消设置 git 相关的变量),否则拉取会变得混乱。
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.这是一个 WebHook 也许可以帮助你。我认为它完全符合您的要求: Remote Server WebHook
Here is a WebHook that maybe could help you. I think it does exactly what you're looking for: Remote Server WebHook