将 Git 存储库从 GitHub 分叉到 GitLab

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50973048/
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-09 05:18:10  来源:igfitidea点击:

Forking Git repository from GitHub to GitLab

gitgithubgitlabgit-fork

提问by Cimlman

Suppose that I would like to implement a fix to a project of someone else. That project resides on GitHub.

假设我想对其他人的项目实施修复。该项目位于 GitHub 上。

I could create a fork on GitHub and implement the fix.

我可以在 GitHub 上创建一个分支并实施修复。

However, I would like to create my fork on GitLab rather than on GitHub.

但是,我想在 GitLab 而不是 GitHub 上创建我的 fork。

Is that possible? How?

那可能吗?如何?

I have read this article: https://about.gitlab.com/2016/12/01/how-to-keep-your-fork-up-to-date-with-its-origin/

我已经阅读了这篇文章:https: //about.gitlab.com/2016/12/01/how-to-keep-your-fork-up-to-date-with-its-origin/

Anyway, I am not sure what should I do in my case.

无论如何,我不确定我应该怎么做。

  • Should I just create a fork on GitLab of the project from GitHub somehow?
  • Or should I create a mirror on GitLab of the project from GitHub?
  • Or should I create a mirror on GitLab and then fork the mirror?
  • Or should I do something completely different?
  • 我应该以某种方式在 GitHub 的项目的 GitLab 上创建一个分支吗?
  • 或者我应该在 GitHub 的项目的 GitLab 上创建一个镜像?
  • 或者我应该在 GitLab 上创建一个镜像然后分叉镜像?
  • 或者我应该做一些完全不同的事情?

What is the correct approach.

什么是正确的做法。

Thanks.

谢谢。

UPDATE

更新

Repository mirroring on GitLab does not make sense probably. I can create a mirror of MY GitHub repository on GitLab but I cannot create a mirror of a repository of someone else.

GitLab 上的存储库镜像可能没有意义。我可以在 GitLab 上创建我的 GitHub 存储库的镜像,但我无法创建其他人的存储库的镜像。

https://docs.gitlab.com/ee/workflow/repository_mirroring.html

https://docs.gitlab.com/ee/workflow/repository_mirroring.html

This is what I have done so far:

这是我到目前为止所做的:

I have cloned the original GitHub project to my local machine. I have commited the fix to a new branch in my local repository. I have created an empty project on GitLab. I have set origin in my local repository to that empty project on GitLab and pushed both branches to GitLab. I have set upstream in my local repository to the GitHub repository.

我已将原始 GitHub 项目克隆到我的本地机器上。我已将修复提交到本地存储库中的新分支。我在 GitLab 上创建了一个空项目。我已将本地存储库中的 origin 设置为 GitLab 上的那个空项目,并将两个分支推送到 GitLab。我已将本地存储库中的上游设置为 GitHub 存储库。

When I want to get new commits from the original GitHub repository to the repository on GitLab (i.e. sync the repositories), I can do this using my local repo as an intermediate step. However, there is no direct connection between the repo on GitHub and the repo on GitLab. Is my setup correct? Is there any difference if I make a fork on GitHub?

当我想从原始 GitHub 存储库向 GitLab 上的存储库获取新提交时(即同步存储库),我可以使用本地存储库作为中间步骤来完成此操作。但是,GitHub 上的 repo 和 GitLab 上的 repo 之间没有直接联系。我的设置正确吗?如果我在 GitHub 上 fork 有什么区别吗?

回答by Chris Watts

If you just want to track changes, first make an empty repository in GitLab (or whatever else you may be using) and clone it to your computer.

如果您只想跟踪更改,请首先在 GitLab(或您可能使用的任何其他工具)中创建一个空存储库并将其克隆到您的计算机。

Then add the GitHub project as the "upstream" remote with:

然后将 GitHub 项目添加为“上游”远程:

git remote add upstream https://github.com/user/repo

Now you can fetch and pull from the upstream should there be any changes. (You can also push or merge to it if you have access rights.)

现在,如果有任何更改,您可以从上游获取和拉取。(如果您有访问权限,您也可以推送或合并到它。)

git pull upstream master

Finally, push back to your own GitLab repository:

最后,推回您自己的 GitLab 存储库:

git push origin master

If you don't want to manually pull upstream/push origin, GitLab offers a mirroring ability in Settings => Repository => Mirroring repositories.

如果您不想手动拉取上游/推送源,GitLab 在 Settings => Repository => Mirroring repositories 中提供了镜像功能。

回答by aksh1618

The browser-only way:

仅浏览器方式:

  1. Create a new project in Gitlab (Just an empty project with a name is fine)
  2. Go to Settings -> Respository
  3. Enter GitHub URL under 'Mirroring repositories'
  4. Make sure 'Mirror direction' is 'Pull'
  5. Press 'Mirror repository' button
  6. Press the sync icon next to the entry that appears
  1. 在 Gitlab 中创建一个新项目(只需一个带有名称的空项目即可)
  2. 转到设置-> 存储库
  3. 在“镜像存储库”下输入 GitHub URL
  4. 确保“镜像方向”是“拉”
  5. 按“镜像存储库”按钮
  6. 按出现的条目旁边的同步图标

回答by Daithí

Forking a private github repository is possible.

分叉私有 github 存储库是可能的。

  1. Click new project
  2. Select Import
  3. Select github
  4. OAuth2 used to authenticate and auto create gitlab app
  5. Select project to fork
  1. 点击新建项目
  2. 选择导入
  3. 选择github
  4. OAuth2 用于验证和自动创建 gitlab 应用程序
  5. 选择要分叉的项目

^ I've just done this with a private repo on github, imported successfully (inc branches etc). Imported project is automatically kept private ;)

^ 我刚刚在 github 上使用私人仓库完成了这项工作,并成功导入(公司分支机构等)。导入的项目会自动保密;)