简体   繁体   English

使用中央Git存储库进行部署

[英]Deploys using central Git repository

I have created a central bare Git repository managed by GitLab for our developers to push changes to. 我创建了一个由GitLab管理的中央裸Git存储库,供我们的开发人员将更改推送到其中。 I have subsequently pushed a "test" branch to this central repository. 随后,我将“测试”分支推送到该中央存储库。 Now I need to pull or export from this repository to a local filesystem to serve the "test" site files. 现在,我需要从此存储库中提取或导出到本地文件系统,以服务“测试”站点文件。 I'd use the same flow for merging changes into staging and production branches. 我将使用相同的流程将更改合并到暂存和生产分支中。

What's the best practice way to set up my web server to pull the test branch (and only the test branch?) code down from the central repository to the local file system? 设置Web服务器以将测试分支(仅测试分支)代码从中央存储库拉到本地文件系统的最佳实践方法是什么? Do I clone the repository? 是否克隆存储库? Do a git init then git pull URL ? 做一个git init然后git pull URL吗? Is there any way to force this local file system to only ever update from the test branch or is that not good/standard practice? 是否有任何方法可以强制此本地文件系统仅从测试分支进行更新,或者这不是好习惯/标准做法?

Is it bad practice to serve files in a Git repository and should I be exporting instead? 在Git存储库中提供文件是一种不好的做法,应该改为导出吗?

One solution would be to define a gitlab webhook , which would send a JSON message to your web server with the relevant information (ie commits and branch which were just pushed). 一种解决方案是定义一个gitlab webhook ,它将与相关信息(即刚刚推送的提交和分支)一起发送JSON消息到您的Web服务器。

Your web server, listening to those JSON messages, would then: 然后,您的Web服务器将侦听这些JSON消息:

  • go to the right repo (I would recommend 3 separate non-bare repo for your web server to monitor, each one with a different url, instead of trying to do everything in just one repo) 转到正确的存储库(我建议您为Web服务器监控3个单独的非裸存储库,每个存储库都使用不同的url,而不是尝试仅在一个存储库中完成所有操作)
  • git fetch , and merge the right origin/branch to branch (like origin/test to test ). git fetch ,并将正确的origin/branch合并到branch (如origin/test to test )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM