使用 Git Push 自动拉取远程服务器?

发布于 2024-08-24 01:28:06 字数 326 浏览 10 评论 0原文

这就是我想要做的:

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情魔剑神 2024-08-31 01:28:06

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

  • 从 GitHub 到 Web 服务器上的裸(空工作树)存储库
  • 从 Web 服务器上的裸存储库到“实时” “ 存储库(带有代表您网站的工作树),

然后您可以将其与“实时”存储库上的钩子关联起来以更新自身(通过“git merge”,将裸存储库的内容合并到“实时”存储库) ,每当你的裸仓库推送任何内容时。

你得到了你想要的效果:任何对你的 GitHub 存储库的推送(我想是针对某个分支)都会触发你的“实时”Web 服务器存储库的刷新。

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.

不一样的天空 2024-08-31 01:28:06

我已经制作了几乎完全按照这种方式工作的东西,除了接收推送的“远程”存储库与随后拉取的存储库位于同一台机器上。确实(并且很重要)完全相同的用户组对两个存储库具有权限。 (但这应该没问题;你不希望随机的人推送你的存储库。)无论如何,我只是让 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.

佞臣 2024-08-31 01:28:06

这是一个 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文