Mirroring from Gitlab to Gitub

I am using a private Gitlab instance to store all my code. But since most of the staff that work with me now have a Github account, I would really like to see me move around and mirror the Gitlab repository on Github.

My situation:

  • the server running Gitlab (Omnibus)
  • a Github account for which I will create an organization where I and my staff can be organized together.

I know there is a switch --mirror

in git, but I'm not sure how it works. The documentation I found on the Internet was very fascinating ... So it would be nice if someone could help me. :)

+14


source to share


3 answers


This previous Stack Overflow question is about how to move your repository from another service to GitHub, the first answer is how to do it from the command line, and the second and third are more user-friendly ways which unfortunately won't work for you if your GitLab instance is on your local server (which seems to be your case).

However, you can "import" your repository from the command line to GitHub as explained in the GitHub docs , this is the recommended way as GitHub offers this as an alternative to using its GitHub Importer tool (as highlighted in a previous SO question)

List of steps taken from the documentation:



  1. Create a new repository that you want to push to GitHub.
  2. Create a local clone from your GitLab server:

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

A clean clone is an exact copy, without a working directory for editing files, so it is a clean export.

  1. Go to that directory and then click it with the flag --mirror

    . The mirror flag ensures that links (branches / tags) are copied to GitHub.

    cd *repo.git*

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

  2. Finally, delete the local repository you created.

    cd ..

    rm -rf repo.git

+10


source


GitLab now has the ability to do this from the UI, go to the Settings-> repository of your repo:

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



Then find the Mirror Storage option and click Expand. What you want to do is select the "Push" mirror direction and fill in this url:

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

+7


source


Another option is to add an additional URL to origin

:

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

      

When you click on a source, it will push both the original source (gitlab) and the one added above (github).

0


source







All Articles