【问题标题】:How to change the URL on a local repository from GitLab to GitHub?如何将本地存储库上的 URL 从 GitLab 更改为 GitHub?
【发布时间】:2019-12-24 14:28:33
【问题描述】:

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

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

我试过命令:

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

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

【问题讨论】:

  • git remote set-url origin <new-url> 是更改远程地址的正确命令。如果您更喜欢使用 ssh,请将 new-url 设置为 git@github.com:USERNAME/REPOSITORY.git 格式。对于 https,它看起来像这样 https://github.com/USERNAME/REPOSITORY.git

标签: git git-push git-pull git-remote git-fetch


【解决方案1】:

使用以下命令检查存储库链接到的内容: git remote -v

如果它链接到多个 url,则可能是问题所在。尝试使用以下命令删除不需要的 url: git remote rm <destination>

然后通过再次运行git remote -v 再次检查链接了哪些存储库。

【讨论】:

    【解决方案2】:

    如果你想同时使用 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
    

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

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

    另请参阅 "How to change the URI (URL) for a remote Git repository?""What exactly does the “u” do? “git push -u origin master” vs “git push origin master”"。

    【讨论】:

      猜你喜欢
      • 2010-10-26
      • 1970-01-01
      • 2010-11-29
      • 1970-01-01
      • 2019-02-02
      • 2018-12-01
      • 1970-01-01
      相关资源
      最近更新 更多