【问题标题】:how to change remote fetch url in git如何在git中更改远程获取url
【发布时间】:2020-09-26 03:48:10
【问题描述】:

我的 git 远程仓库如下所示:

$ git remote -v
origin  https://github.com/jiangxiaoqiang/dolphin-scripts.git (fetch)
origin  https://github.com/jiangxiaoqiang/dolphin-scripts.git (push)
origin  https://gitee.com/jiangxiaoqiang/dolphin-scripts.git (push)

现在我想默认从 gitee 获取,如何将获取 url 更改为 gitee

【问题讨论】:

标签: git git-remote git-fetch


【解决方案1】:

试试

git remote add origin https://gitee.com/jiangxiaoqiang/dolphin-scripts.git --mirror=fetchde here

如果您已经有源,您可能需要清理远程名称并读取(3 个命令):

git remote origin remove
git remote add origin https://gitee.com/jiangxiaoqiang/dolphin-scripts.git
git remote set-url --push origin https://github.com/jiangxiaoqiang/dolphin-scripts.git

【讨论】:

  • 不起作用。$ git remote add origin https://gitee.com/jiangxiaoqiang/dolphin-scripts.git --mirror=fetch fatal: remote origin already exists.@Json Phillips
  • 您可能必须先删除原点,然后再添加它,即 git remote remove origin
  • 你好@Jason,不建议单独使用--push URL。最好创建一个单独的遥控器用于推送/获取以支持三角工作流
【解决方案2】:

正如@Jason Phillips 所说,你必须先做:

git remote remove origin

这将删除源远程和与之关联的 URL。接下来你做:

git remote add origin https://gitee.com/jiangxiaoqiang/dolphin-scripts.git

这将添加一个名为origin 的新远程,与gitee URL 关联。 现在添加另一个远程(我们称之为extra),它将用于推送到 GitHub

git remote add extra https://github.com/jiangxiaoqiang/dolphin-scripts.git

现在您可以通过 git push extra 推送到 GitHub 和 git fetch origingit pull origin 分别从 Gitee 获取和拉取更改。

最好的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-18
    • 2011-01-26
    • 2021-05-07
    • 1970-01-01
    • 2018-06-06
    相关资源
    最近更新 更多