使用Git将远程仓库的 'origin' 更改为 'upstream'

6

我已经从原始源的 upstream master 存储库克隆了一个 Git 存储库到我的本地计算机。
git remote -v 返回:

origin  https://github.com/project.git (fetch)
origin  https://github.com/project.git  (push)

但我现在知道,我需要将这个 upstreammaster 分支 fork 到我的个人 GitHub 帐户中,然后克隆该分支,创建一个新的分支,开始编码(这样我就不会直接对 upstream 存储库进行更改,而是对自己 fork 的 origin 存储库进行更改)。我已经将 upstreammaster 分支 fork 到了我的 GitHub 个人资料中,但不知道该怎么继续。我需要让 git remote -v 看起来像这样:

origin    https://github.com/myGitHubProfile/project.git (fetch)
origin    https://github.com/myGitHubProfile/project.git (push)
upstream    https://github.com/project.git (fetch)
upstream    https://github.com/project.git  (push)

如何实现这一目标,考虑到我已经从原始源代码克隆了upstream master并将其设置为origin


1
参见 Ondrej K. 的回答 中的命令序列,但我要补充一点,如何获得远程库并不重要:您可以删除所有远程库并重新添加它们,唯一的真正成本是您多输入了几个命令。在运行 git fetch --allgit remote update 之后,最终结果都是您将从两个存储库中获取所有提交,并通过适当的远程跟踪名称找到它们。 - torek
1个回答

14

看起来你正在寻找:

git remote rename origin upstream
git remote add origin https://github.com/myGitHubProfile/project.git

给"old" origin 远程仓库一个新的upstream名称,并添加一个名为origin的新远程仓库。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接