[英]How do you do an automatic git pull on remote server?
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.在我开始之前,我知道有很多与这个问题类似的问题,但我真的很难找到一个简洁、安全、最佳的实践,因为对它们的反馈是如此广泛。
I have git installed on my local machine and the remote server.我在本地机器和远程服务器上安装了 git。 I can push mods to the development branch to git.
我可以将 mod 推送到开发分支到 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.
问题是当从我的本地机器推送更改时,我无法让远程服务器自动更新。
git init
or git init --bare
?git init
还是git init --bare
? I don't plan on having updates made on the server itself. I am a web developer by nature, so git and sysadmin tasks are generally the bane of my existence.我本质上是一名 Web 开发人员,所以 git 和 sysadmin 任务通常是我存在的祸根。 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.
我已经大约 16 个小时了,并且已经正式达到了“无进展地兜圈子”的点。
You can do this quite easily with GitHub service hooks.您可以使用 GitHub 服务挂钩轻松完成此操作。
You ll need to create one more file that will handle the process of performing the git pull.您需要再创建一个文件来处理执行 git pull 的过程。 Add a new file, called github.php (or anything you wish ), and add:
添加一个名为 github.php 的新文件(或任何您希望的文件),然后添加:
<?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” Eg http://demo.test.com/myfolder/github.php
然后,转到
Services Hooks -> Post-Receive URL
并将Services Hooks -> Post-Receive URL
复制到该文件,并将其粘贴到“Post-Receive URL”中,例如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
.所以,当你推送时,GitHub 会自动访问这个 URL,从而导致你的服务器执行
git pull
。
To see this in more details to go to this tutorial要查看更多详细信息,请转到本教程
I had the same exact issue, strong in code and development skills, weak in sysadmin skills.我有同样的问题,代码和开发技能强,系统管理员技能弱。 When I was finally ready to push code I had to ask a GitHub rep what their suggested method was, and they responded with Capistrano.
当我终于准备好推送代码时,我不得不询问GitHub代表他们建议的方法是什么,他们回复了 Capistrano。 It's a Ruby application that runs commands (such as git pull) on remote servers, along with pretty much any other command you can imagine.
它是一个Ruby应用程序,可以在远程服务器上运行命令(例如 git pull),以及您可以想象的几乎任何其他命令。
Here a few articles you can read to get more info:您可以阅读以下几篇文章以获取更多信息:
How to compile the Capistrano stack on your *nix system 如何在 *nix 系统上编译 Capistrano 堆栈
Another example of how to deploy code with Capistrano 如何使用 Capistrano 部署代码的另一个示例
Not going to lie, the learning curve was pretty steep, but once you start working with Capistrano, you will see that it works well for pushing code.不会撒谎,学习曲线非常陡峭,但是一旦您开始使用 Capistrano,您就会发现它非常适合推送代码。 I develop my applications in Symfony and I have my Capistrano set-up to pull code, clear cache and clear log files, all in one command from my local machine.
我在 Symfony 中开发我的应用程序,并且我有我的 Capistrano 设置来提取代码、清除缓存和清除日志文件,所有这些都来自我本地机器的一个命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.