git如何处理来自两个不同远程回购的相同分支名称? [英] How does git deal with identical branch names from two different remote repo?

查看:344
本文介绍了git如何处理来自两个不同远程回购的相同分支名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 git remote add 为回购设置了两个远程,并且这两个回购包含一个具有相同名称的分支。如何使用git checkout git checkout 切换到哪个分支?

解决方案


当我使用git checkout切换到哪个分支时,git如何知道哪个分支会使用?

它没有。通常,如果存在歧义,例如在这种情况下,两个遥控器(原始和上游2)都有 devel 分支:

  $ git branch -a 
* master
遥控器/ origin / HEAD - >起源/大师
遥控器/原产地/开发者
遥控器/原产地/主人
遥控器/上游2 /开发者
遥控器/上游2 /主人



如果我只是尝试 git checkout devel 我得到:

  $ git checkout devel 
错误:pathspec'devel'与git已知的任何文件都不匹配。

我需要明确说明:

  $ git checkout -b devel remotes / upstream2 / devel 
Branch devel设置为通过重新绑定来跟踪远程分支devel from upstream2。
转换到一个新分支'devel'

比较这种情况,我只有一个遥控器:

  $ git branch -a 
* master
遥控器/原点/ HEAD - > ;起源/大师
遥控器/原产地/开发者
遥控器/原产地/主人

然后:

  $ git checkout devel 
分支开发通过重新绑定来跟踪远程分支的开发。
切换到新分支'devel'


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?

解决方案

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'

这篇关于git如何处理来自两个不同远程回购的相同分支名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆