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

问题描述 投票:5回答:2

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

git clone https://github.com/my-github-page/repo-name

现在,由于一段时间过去了,原来的回购所有者已经更新了他的回购,但我的落后。所以,如果我想做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)

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

git fork pull
2个回答
9
投票

你可以试试:

git remote set-url origin /original/repo
git remote set-url --push origin /your/fork

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

当然,另一种更传统的方法是声明另一个遥控器,正如我在"What is the difference between origin and upstream on GitHub?"中详述的那样


1
投票

参考以下问题:github, update forked project

请执行下列操作:

git remote add upstream <url of the repo you cloned from>

此后从上游拉。这会将所有远程更改拉入本地副本。

如果以后再次需要从远程提取更改,则可以再次从上游提取,这次无需再次添加上游URL。

建议阅读:Syncing a fork

© www.soinside.com 2019 - 2024. All rights reserved.