Git push to two remotes

The Problem:

Need a way to share code hosted in a private GitLab repo publicly on GitHub.

The solution:

Use a second Git remote to share a private Git repo publicly on GitHub.


GitLab with its free unlimited private repository hosting and CiCd services offers a great place to host Git repos and build code. GitHub is the defacto home of Open Source code repositories and is also a great way to add to a resume by sharing projects publicly.


  • GitLab account
  • GitHub account
  • Private Git repo hosted on GitLab
  • Public Git repo hosted on GitHub

Verify the current remote

From the GitLab hosted repo:

sandor@theargo> git remote -v
origin (fetch)
origin (push)

Add the second GitHub remote

sandor@theargo> git remote set-url --add --push origin

Verify the remotes

sandor@theargo> git remote -v
origin (fetch)
origin (push)
origin (push)

This is using origin as the remote name for both GitLab and GitHub. Using gitlab and github as the remote names is another possibility and would enable pushing to GitHub only when the project is ready to be published publicly.