9

I have a number of Gitlab projects that I'd also like to store as repos in Github. How can I initialize a new Github repo for a project with an existing Gitlab git config?

I read this on mirroring/moving repos, but I don't want to move anything per se, I just want to have the project exist on both Github and Gitlab.

And if I do have a local project with both a Gitlab and Github git config, how can I specify which to push changes to? How would I specify to perhaps push changes to both at the same time?

Community
  • 1
  • 1
user3871
  • 12,432
  • 33
  • 128
  • 268
  • The link to another stackoverflow question now has an answer how to setup periodic mirrorring of repos from gitlab to github. Direct link to the answer: https://stackoverflow.com/a/56466021/3125367 – user3125367 Apr 03 '23 at 15:27

2 Answers2

14

This is to say you want to be able to deploy to multiple remote repositories if that's the case

To add new repo's run this command

git remote add < shortname > < url >

 git remote add origin-new git@github.com:username/repo-name.git

where:

  • origin-new is the remote server name (it can be any valid string)

  • git@github.com:username/repo-name.git is the url to your online repo

To Show Your Remotes

$ git remote -v

origin  https://gitlab.com/username/repo-name (fetch)
origin  https://gitlab.com/username/repo-name (push)

origin-new  https://github.com/username/repo-name (fetch)
origin-new  https://github.com/username/repo-name (push)

Pushing to Your Remotes

git push < remote > < branch >

$ git push origin master

$ git push origin-new dev

Fetching and Pulling from Your Remotes

git pull < remote >

git fetch < remote >

$ git pull origin

$ git pull origin-new

for more checkout out Git Basics Working with Remotes

2

Open the desired projects in git hub and follow the orders.

There will be 2 sections describing what to do.
The first one is for new project and the second one if for adding existing code.

You simply need to add new remote and the push your code, That's it.

adding-an-existing-project-to-github-using-the-command-line

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Following the second option: `fatal: remote origin already exists.` Also, what about pushing using the git CLI? Git commands for gitlab and github are shared, so doing `git add` will stage for both. And `git push origin dev` for example will push to which one? – user3871 Dec 06 '15 at 06:07
  • 1
    you probably trying to add origin again, give it another name like github or origin2. then simply push to the desired origin, the code will be the same of course – CodeWizard Dec 06 '15 at 06:22