6

I had a repository on GitLab which I also published on GitHub.

As of now all the Git commands I am using are making changes on GitLab. However, I want those commits on GitHub.

I tried the command:

git remote set-url origin git@github.com:repo-url

Can someone suggest me how to set the URL so that commands would work on GitHub and not GitLab?

EvgenKo423
  • 2,256
  • 2
  • 16
  • 23
Marcelo BD
  • 229
  • 3
  • 8
  • `git remote set-url origin ` is right command to change remote address. If you prefer using ssh then set new-url to `git@github.com:USERNAME/REPOSITORY.git` format. For https it would look like this `https://github.com/USERNAME/REPOSITORY.git` – How about nope Aug 19 '19 at 11:17
  • This question is a duplicate of [How to change the URI (URL) for a remote Git repository?](https://stackoverflow.com/q/2432764/11725753) – EvgenKo423 Apr 30 '21 at 10:54

2 Answers2

23

If you want to use both GitHub and GitLab:

git remote add github <your-github-url>  # create a remote for GitHub
git remote add gitlab <your-gitlab-url>  # create another remote for GitLab
git push -u github <local_branch_name>   # set the default upstream to GitHub

If you want to change your remote URL from GitLab to GitHub:

git remote set-url origin <your-github-url>  # use GitHub as your (only) origin

See also "How to change the URI (URL) for a remote Git repository?" and "What exactly does the “u” do? “git push -u origin master” vs “git push origin master”".

SparkFountain
  • 2,110
  • 15
  • 35
2

Check what the repository is linked to with the command: git remote -v

If it is linked to multiple url's that may be the issue. Try to remove the unwanted url with the command: git remote rm <destination>

Then check again which repos are linked, by running git remote -v once more.

Michael
  • 4,538
  • 5
  • 31
  • 58