How does git deal with identical branch names from two different remote repo?

China☆狼群 提交于 2019-12-11 03:49:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!