如何将本地存储库上的 URL 从 GitLab 更改为 GitHub?

Mar*_* BD 3 git git-pull git-push git-fetch git-remote

我在 GitLab 上有一个存储库,我也在 GitHub 上发布了它。

到目前为止,我使用的所有 Git 命令都在 GitLab 上进行了更改。但是,我希望在 GitHub 上进行这些提交。

我试过命令:

git remote set-url origin git@github.com:repo-url
Run Code Online (Sandbox Code Playgroud)

有人可以建议我如何设置 URL 以便命令可以在 GitHub 而不是 GitLab 上运行吗?

Spa*_*ain 9

如果你想同时使用 GitHub 和 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
Run Code Online (Sandbox Code Playgroud)

如果要将远程 URL 从 GitLab 更改为 GitHub

git remote set-url origin <your-github-url>  # use GitHub as your (only) origin
Run Code Online (Sandbox Code Playgroud)

另请参阅“如何更改远程 Git 存储库的 URI (URL)?” ““u”到底是做什么的?“git push -u origin master”与“git push origin master” “。