如何更改git存储库的获取URL.

hid*_*dar 7 git pull git-fork

我有一个github配置文件,我把某人的存储库分成了我的.在本地我已经克隆了这个存储库

git clone https://github.com/my-github-page/repo-name
Run Code Online (Sandbox Code Playgroud)

现在,由于一段时间过去了,原来的回购所有者已经更新了他的回购,但我的落后.所以,如果我愿意git pull将他的变化合并到我的.但我想把我的变化从当地推到我的.

简单来说,如果我这样做,git remote show origin我得到这个:

[root@localhost xxx]# git remote show origin
* remote origin
  Fetch URL: https://github.com/my-github-profile/xxx
  Push  URL: https://github.com/my-github-profile/xxx
  HEAD branch: master
  Remote branches:
    1.0          tracked
    master       tracked
    system_tests tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)
Run Code Online (Sandbox Code Playgroud)

现在我想将FETCH URL更改为repo的原始src.因为原件已更新,但我的叉子落后了

Von*_*onC 13

你可以试试:

git remote set-url origin /original/repo
git remote set-url --push origin /your/fork
Run Code Online (Sandbox Code Playgroud)

这样,只有fetch引用原始repo URL.

当然,另一种更传统的方法是声明另一个遥控器,正如我在"GitHub上的原点和上游之间有什么区别?"中详述的那样.

  • 可以用,但在我看来看起来很丑。我真的很期待 `git remote set-url --fetch` 选项,很遗憾它不存在 (3认同)
  • @TheGodfather 这在 https://public-inbox.org/git/xmqqftwp47nb.fsf@gitster-ct.c.googlers.com/T/“remote: add --fetch option to git remote set-url”中进行了讨论,但是……否认了。 (2认同)