你如何做一个远程服务器上的自动git拉? [英] How do you do an automatic git pull on remote server?

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

问题描述

在开始之前,我知道有很多类似这个问题的问题,但是我很难找到一个简洁,安全和最佳实践,因为对它们的反馈已经非常多样。

b
$ b

我想要做什么:
1)在开发分支上完成本地机器上的工作。
2)将更改推送到git。 Git发布到webhook网址,并自动让我的远程服务器在开发网站上获取更改。
3)在开发网站上进行QA并确认为正确后,将主分支推送至生产站点(与开发站点位于同一服务器上)。

我在哪里:
我的本地计算机和远程服务器上安装了git。我可以推动mods到开发分支去git。在远程服务器上,我可以获取更新,并且它像魅力一样工作。问题是我无法让远程服务器在我的本地机器上发生更改时自动更新。



我的问题是:
1)对于远程服务器开发网站目录,我应该git init或git init --bare?我不打算在服务器上进行更新。我希望我的开发团队在本地工作并将mod推送到服务器。我相信我需要使用git init,因为需要工作树来为git存储库设置一个远程别名,但我想确认一下。
2)我很确定从git问题的webhook帖子是由于用户权限。我该如何安全解决这个问题?我已经阅读了许多教程,建议更新git钩子文件,但我觉得这是一个比我需要采取的措施更激烈。我希望能够让webhook击中一个可以安全地拖拽文件的URL,而无需添加一堆代码(如果可能的话)。



我是一个web开发者本性,所以git和sysadmin任务通常是我存在的祸根。再次,我知道这个问题与其他问题类似,但我还没有找到全面,简洁,安全和最合乎逻辑的方法来解决问题。我在大约16个小时的时间里,并且正式击中了没有进展的圈子。



非常感谢您的帮助!

解决方案

您可以使用GitHub服务钩子轻松完成此操作。

您需要创建一个文件来处理执行git pull的过程。添加一个名为github.php的新文件(或任何你想要的),并添加:

 <?php`git pull `; 

保存该文件,并将其上传到服务器上的存储库目录。然后,转到服务挂钩 - >接收后的URL 并将URL复制到该文件,并将其粘贴到Post-Receive URL中。 http://demo.test.com/myfolder/github.php



因此,当您推送时,GitHub会自动访问这个URL,从而导致你的服务器执行 git pull



更详细的信息去本教程


Before I begin, I know there are a lot of questions similar to this one, but I am really having difficulty finding a concise, secure, best practice since the feedback on them has been so widely varied.

What I want to do: 1) Complete work on my local machine on a development branch. 2) Push changes to git. Git posts to a webhook URL and automatically has my remote server pull the changes on a development site. 3) Once QA'd and confirmed to be proper on the development site, push the master branch to the production site (on the same server as the development site).

Where I am at: I have git installed on my local machine and the remote server. I can push mods to the development branch to git. On the remote server, I can pull the updates and it works like a charm. The problem is that I cannot get the remote server to automatically update when changes are pushed from my local machine.

My questions are: 1) For the remote server development site directory, should I git init or git init --bare? I don't plan on having updates made on the server itself. I would like my dev team to work locally and push mods to the server. I believe I need to use git init as the working tree is needed to set-up a remote alias to the git repository, but I wanted to confirm. 2) I am pretty sure the webhook post from git issue is due to user privileges. How can I safely get around this? I have read many tutorials that suggest updating git hook files, but I feel as though that is more drastic of a measure than I need to take. I would love to be able to have the webhook hit a URL that safely pulls the files without adding a boatload of code (if it is possible).

I am a web developer by nature, so git and sysadmin tasks are generally the bane of my existence. Again, I know this question is similar to others, but I have yet to find a comprehensive, concise, secure, and most logical approach to resolving the issue. I am about 16 hours in and have officially hit the "going in circles with no progress" point.

Thanks very much in advance for all of your help!

解决方案

You can do this quite easily with GitHub service hooks.

You ll need to create one more file that will handle the process of performing the git pull. Add a new file, called github.php (or anything you wish ), and add:

<?php `git pull`;

Save that file, and upload it to the repository directory on your server. Then, go to Services Hooks -> Post-Receive URL and copy the URL to that file, and paste it into the "Post-Receive URL" E.g. http://demo.test.com/myfolder/github.php

So, when you push, GitHub will automatically visit this URL, thus causing your server to perform a git pull.

To see this in more details to go to this tutorial

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

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