Mirroring from Gitlab to Github

江枫思渺然 提交于 2019-12-02 19:30:22
matrixanomaly

This previous StackOverflow question 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).

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 alternative to using their GitHub Importer tool (which is highlighted in that previous SO question)

A run down of steps as taken from the documentation:

  1. Create a new repository you 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

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 --mirror flag. 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

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

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:

https://yourUserNameInGitHub@github.com/yourUserNameInGitHub/yourRepoName.git

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

git remote set-url --add origin git@github.com:<USERNAME>/<PROJECTNAME>.git

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!