如何更改存储库链接到的fork

时间:2012-07-23 19:59:23

标签: git github

我在MAIN/repo.git收到了一个回购邮件,我把它分给了FORK/repo.git。我将这两个repos克隆到我的计算机上用于不同的目的。

使用Github for Windows,一个错误似乎已经将FORK/repo.git转换为MAIN/repo.git,就像我git remote show origin一样,Fetch URL和Push URL设置为主回购。如何切换回来,以便本地计算机上的相应文件夹指向FORK/repo.git,而不是MAIN/repo.git

1 个答案:

答案 0 :(得分:79)

最简单的方法是在FORK的本地克隆中使用命令行git remote

git remote rm origin
git remote add origin https://github.com/user/FORK.git

或者,在一个命令中,如GitHub article所示:

git remote set-url origin https://github.com/user/FORK.git

更好的做法是:

  • 保持远程引用原始仓库
  • 让你的工作在新的分支机构(将有上游分支跟踪你的分支)

所以:

git remote rename origin upstream
git branch -avv # existing branches like master are linked to upstream/xxx

git remote add origin https://github.com/user/FORK.git
git checkout -b newFeatureBranch

每当您需要根据原始仓库的最新发展更新您的前叉时:

git checkout master
git pull # it pulls from upstream!
git checkout newFeatureBranch
git rebase master # safe if you are alone working on that branch
git push --force # ditto. It pushes to origin, which is your fork.