git 从 Gitlab 镜像到 Github

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

Mirroring from Gitlab to Github

gitgithubgitlabmirror

提问by Ingwie Phoenix

I have been using a private Gitlab instance to hold all my code. But since most of the staff that work with me now have a Github account, i would really like to get moving and mirror my Gitlab repo to Github.

我一直在使用一个私有的 Gitlab 实例来保存我的所有代码。但是由于与我一起工作的大多数员工现在都有一个 Github 帐户,我真的很想开始行动并将我的 Gitlab 存储库镜像到 Github。

My situation:

我的情况:

  • a server running Gitlab (Omnibus)
  • a Github account for which I'll create an organization for where me and my staff can be organized together.
  • 运行 Gitlab (Omnibus) 的服务器
  • 一个 Github 帐户,我将为其创建一个组织,以便将我和我的员工组织在一起。

I know that there is the --mirrorswitch in git, but I am not really sure how this is ment to work. Documentation I found online was very wonky... So it would be nice if someone could help me out. :)

我知道--mirrorgit中有开关,但我不确定这是如何工作的。我在网上找到的文档非常不稳定......所以如果有人能帮助我就好了。:)

回答by knocte

GitLab has now an option to do this from the UI, go to the Settings->Repository of your repo:

GitLab 现在有一个选项可以从 UI 执行此操作,请转到您的存储库的 Settings->Repository:

https://gitlab.com/yourUserNameInGitLab/yourRepoName/settings/repository

https://gitlab.com/yourUserNameInGitLab/yourRepoName/settings/repository

Then find the option "Mirror a repository" and click on expand. What you want to do is choose the "Push" mirror direction and fill this URL:

然后找到选项“镜像存储库”并单击展开。你要做的是选择“Push”镜像方向并填写这个URL:

https://[email protected]/yourUserNameInGitHub/yourRepoName.git

https://[email protected]/yourUserNameInGitHub/yourRepoName.git

回答by matrixanomaly

This previous StackOverflowquestion addresses how to move your repository from another service over to GitHub, the first answer there addresses how to do it via command line, and the second and third are more user friendly ways, which unfortunately will not work for you if your GitLab instance is on your local server(which seems to be your case).

之前的 StackOverflow问题解决了如何将您的存储库从另一个服务转移到 GitHub,那里的第一个答案解决了如何通过命令行进行操作,第二个和第三个是更用户友好的方式,不幸的是,如果您的GitLab 实例位于您的本地服务器上(这似乎是您的情况)。

You can however 'import' your repository from the command line to GitHub as explained by GitHub docs, this is the suggested way as GitHub offers this as an alternativeto using their GitHub Importer tool (which is highlighted in that previous SO question)

但是,您可以按照GitHub docs 的说明将您的存储库从命令行“导入”到 GitHub ,这是建议的方式,因为 GitHub提供此方法作为使用其 GitHub Importer 工具的替代方法(在上一个 SO 问题中突出显示)

A run down of steps as taken from the documentation:

从文档中提取的步骤:

  1. Create a new repositoryyou want to push to in GitHub.
  2. Make a local bare clone from your GitLab server:

    git clone --bare https://githost.org/extuser/repo.git

  1. 在 GitHub 中创建要推送到的新存储库
  2. 从您的 GitLab 服务器制作本地裸克隆:

    git clone --bare https://githost.org/extuser/repo.git

A bare clone is an exact duplicate, without a working directory for editing files, so it's a clean export.

裸克隆是完全重复的,没有用于编辑文件的工作目录,因此它是一个干净的导出。

  1. Change into that directory and then push it with the --mirrorflag. The mirror flag ensures that references (branches/tags) are copied to GitHub.

    cd *repo.git*

    git push --mirror https://github.com/ghuser/repo.git

  2. Finally remove the local repository you made.

    cd ..

    rm -rf repo.git

  1. 切换到该目录,然后使用--mirror标志推送它。镜像标志确保引用(分支/标签)被复制到 GitHub。

    cd *repo.git*

    git push --mirror https://github.com/ghuser/repo.git

  2. 最后删除您创建的本地存储库。

    cd ..

    rm -rf repo.git

回答by Kris

Another options is to add an additional URL to the origin:

另一种选择是向 中添加额外的 URL origin

git remote set-url --add origin [email protected]:<USERNAME>/<PROJECTNAME>.git

When you push to origin it will push to both the original origin (gitlab) and the one added above (github).

当您推送到原点时,它将同时推送到原始原点 (gitlab) 和上面添加的原点 (github)。