如果我使用 git remote add 为回购设置了两个远程,并且两个回购包含一个具有相同名称的分支。当我使用 git checkout 切换到它时,git如何知道我打算使用哪个repo?
答案 0 :(得分:6)
当我使用git checkout切换到它时,git如何知道我打算使用哪个repo?
没有。通常,如果存在歧义,例如在这种情况下,两个遥控器(“origin”和“upstream2”)都有一个devel
分支:
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/devel
remotes/origin/master
remotes/upstream2/devel
remotes/upstream2/master
如果我只是尝试git checkout devel
我得到:
$ git checkout devel
error: pathspec 'devel' did not match any file(s) known to git.
我需要明确:
$ git checkout -b devel remotes/upstream2/devel
Branch devel set up to track remote branch devel from upstream2 by rebasing.
Switched to a new branch 'devel'
将此与我只有一个遥控器的情况相比较:
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/devel
remotes/origin/master
然后:
$ git checkout devel
Branch devel set up to track remote branch devel from origin by rebasing.
Switched to a new branch 'devel'