git GitLab fork 远程公共仓库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28054934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:41:51  来源:igfitidea点击:

GitLab fork remote public repo

gitgithubgitlab

提问by Wayne Weibel

My organization has a dedicated machine for our GitLab install. I regularly work with other public projects (Drupal.org and Github). I would like to have a repo on our GitLab with a branch that would track the remote Drupal or Github project, in addition to having our own development and production branches.

我的组织有一台专用机器用于我们的 GitLab 安装。我经常与其他公共项目(Drupal.org 和 Github)合作。除了拥有我们自己的开发和生产分支之外,我还想在我们的 GitLab 上有一个仓库,其中有一个分支可以跟踪远程 Drupal 或 Github 项目。

Want this to be on the GitLab server (machine) so a developer is not responsible for tracking and updating from the public remote.

希望这在 GitLab 服务器(机器)上,因此开发人员不负责从公共远程跟踪和更新。

Essentially, fork public repo tracked on 'master', with internal branches 'devel' and 'prod'; developers only cloning internal devel branch. Then have the ability to pull from remote to master, then merge to other internal branches as desired. Can that be accomplished via the web interface or with hooks? or ...

本质上,fork public repo 在“master”上跟踪,内部分支为“devel”和“prod”;开发人员只克隆内部开发分支。然后有能力从远程拉到主,然后根据需要合并到其他内部分支。这可以通过网络界面或钩子来完成吗?或者 ...

Following the answer to Create a fork of public git repo for githubit would seem that it would need to be a script to pull from public remote to local, then push to GitLab master, with the script set as a cron job. Yeah?

按照为 github 创建一个公共 git repo 的分支的答案,它似乎需要一个脚本来从公共远程拉到本地,然后推送到 GitLab 主站,并将脚本设置为 cron 作业。是的?

回答by petrpulc

Fork is nothing but a new repository with added remote

Fork 只不过是一个新的存储库,添加了远程

There are three main ideas that need to be understood:

需要理解三个主要思想:

  • each Git repository is a standalone repository
  • "fork" is a fancy word for repository with remote pointing to original repository
  • GitLab is nothing more than a user interface to a real Git repository on a filesystem
  • 每个 Git 存储库都是一个独立的存储库
  • “fork”是远程指向原始存储库的存储库的一个花哨词
  • GitLab 只不过是文件系统上真实 Git 存储库的用户界面

Therefore, if you insist that some branch(es) should be kept up to date on your server with the branches on remote (git:// or http(s)://) you can add new remote to your real git repository (usually located at /home/git/repositories, check your gitlab.yml) and set-up a cron to pull changes from such remote.

因此,如果您坚持认为服务器上的某些分支应该与远程(git:// 或 http(s)://)上的分支保持同步,您可以将新的远程添加到您的真实 git 存储库(通常位于 /home/git/repositories,检查你的 gitlab.yml)并设置一个 cron 来从这样的远程获取更改。

BUT, a lot of things may go wrong if the pull won't be a fast-forward and merge would be needed.

但是,如果拉动不是快进并且需要合并,那么很多事情可能会出错。

A solution to that would be to fetch the remote and reset instead, but this time all your changes would be lost.

一个解决方案是获取遥控器并重置,但这一次您的所有更改都将丢失。

Better do it all by hand

最好手工完成

If only possible, a much better solution would be to dedicate a bit of time and pull the changes by hand, check for consistencies and push to your local copy.

如果可能的话,一个更好的解决方案是花一些时间手动拉取更改,检查一致性并推送到您的本地副本。

回答by Xin Meng

Maybe you can try the GitLab mirroring feature: https://docs.gitlab.com/ee/workflow/repository_mirroring.html

也许你可以试试 GitLab 镜像功能:https://docs.gitlab.com/ee/workflow/repository_mirroring.html

it supports pull from the remote repo:

它支持从远程仓库拉取:

https://docs.gitlab.com/ee/workflow/repository_mirroring.html#pulling-from-a-remote-repository-starter

https://docs.gitlab.com/ee/workflow/repository_mirroring.html#pulling-from-a-remote-repository-starter