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

zeb*_*bra 44 git github

我有一个回复电话,MAIN/repo.git我已经把它分叉了FORK/repo.git.我将这两个repos克隆到我的计算机上用于不同的目的.

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

Von*_*onC 84

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

git remote rm origin
git remote add origin https://github.com/user/FORK.git
Run Code Online (Sandbox Code Playgroud)

或者,在一个命令中,如此GitHub文章中所示:

git remote set-url origin https://github.com/user/FORK.git
Run Code Online (Sandbox Code Playgroud)

更好的做法是:

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

所以:

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
Run Code Online (Sandbox Code Playgroud)

每当你需要根据原始回购的最新进展更新你的fork:

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.
Run Code Online (Sandbox Code Playgroud)

  • @zebra不,不会覆盖任何东西.这纯粹是本地配置设置更改. (4认同)