Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mirror a GitLab repository to GitHub using SSH keys?

Tags:

git

github

gitlab

GitLab has a mirror feature:

https://docs.gitlab.com/ee/user/project/repository/mirror/

and GitHub does not support simple password authentication. I tried to follow

https://meesvandongen.nl/posts/mirror-gitlab-github

Using the target url

ssh://[email protected]:stefaneidelloth/mirror_demo.git

and SSH public key as authentication method.

However, I get an error

Remote mirrors url is blocked: URI is invalid 

from GitLab.

If I specify the target url

https://github.com/stefaneidelloth/mirror_demo.git

I am not able to select SSH public key as authentication method.

=> What are the right settings to mirror a GitLab project to a GitHub project (without PREMIUM edition of GitLab)?

Edit

The second : needs to be replaced with a /.

Suggested by GitHub:

enter image description here

Adding ssh:// prefix is not enough.

Wrong: ssh://[email protected]:stefaneidelloth/mirror_demo.git

Still need to replace : after github.com:

Right: ssh://[email protected]/stefaneidelloth/mirror_demo.git

Then GitLab generates the SSH key for the connection and one needs to copy it to the GitHub project settings (not the user settings), see https://meesvandongen.nl/posts/mirror-gitlab-github

Now I get the next error:

13:get remote references: create git ls-remote: exit status 128, stderr: "ssh connect to host github.com port 22: Connection timed out\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n".

a) Do I need to specify a different port than 22? How? I tried

ssh://[email protected]:443/stefaneidelloth/mirror_demo.git

but that did not help.

b) Do I need to use "Input host keys manually"? What should be specified? I tried to use

SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s

from

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints

but that did not help.

c) I also tried to generate a GitHub AccessToken in the user settings and apply it for the password option of the GitLab Mirror settings. I tried both, https:// and git:// urls. No success.

like image 865
Stefan Avatar asked Feb 05 '26 14:02

Stefan


2 Answers

I got this to work after all.

  1. Yes, you need to manually edit the git SSH URL, as you have shown: ssh://[email protected]/stefaneidelloth/mirror_demo.git
  2. Select SSH public key as authentication method.
  3. Then click mirror repository button
  4. Copy the SSH key generated as shown here: https://meesvandongen.nl/posts/mirror-gitlab-github and https://docs.gitlab.com/ee/user/project/repository/mirror/push.html#set-up-a-push-mirror-from-gitlab-to-github
  5. The key then needs to be added as a Deploy Key to the GitHub Repo, which is done from Settings > Deploy Keys (see figure below)
  6. Click refresh on the mirror. Note that when I first did this, nothing happened, no errors, but also no update. I did it four times and still nothing happened. Then about 27 minutes later, the update happened.

Deploy Keys

like image 97
geoidesic Avatar answered Feb 08 '26 15:02

geoidesic


"ssh connect to host github.com port 22: Connection timed out" suggests that something is blocking port 22 for github.com - perhaps a proxy or firewall. GitHub has a separate hostname (not github.com) for handling SSH traffic over a rarely-blocked port; your URL for that would need to be ssh://[email protected]:443/stefaneidelloth/mirror_demo.git.

like image 38
Jim Redmond Avatar answered Feb 08 '26 16:02

Jim Redmond



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!