问题
If I set up two remote using git remote add for a repo, and the two repo contain a branch with the same name. How does git know which branch of which repo I intend to use when I switch to it using git checkout?
回答1:
How does git know which branch of which repo I intend to use when I switch to it using git checkout?
It doesn't. Typically, if there is ambiguity, such as in this situation where both remotes ("origin" and "upstream2") have a devel
branch:
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/devel
remotes/origin/master
remotes/upstream2/devel
remotes/upstream2/master
If I simply try to git checkout devel
I get:
$ git checkout devel
error: pathspec 'devel' did not match any file(s) known to git.
I need to be explicit:
$ 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'
Compare this to the situation where I have only a single remote:
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/devel
remotes/origin/master
And then:
$ git checkout devel
Branch devel set up to track remote branch devel from origin by rebasing.
Switched to a new branch 'devel'
来源:https://stackoverflow.com/questions/31631726/how-does-git-deal-with-identical-branch-names-from-two-different-remote-repo