无法获得远程分支到本地仓库

时间:2018-03-18 19:24:47

标签: git

每当我在远程仓库中创建一个新分支时,我都无法将其转移到我的本地仓库。

我试过了:

git fetch --all,它实际更新了远程分支,但它们没有显示git branch

git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done是唯一对我有用的东西,但它会抓取远程所有分支。在大型项目中,我最终从git branch

获得了100个分支

2 个答案:

答案 0 :(得分:1)

git branch仅显示您当地的分支机构。指定-r以显示远程分支,或-a以显示本地和远程分支。

要签出远程分支的本地副本,请运行git checkout <branch>,其中<branch>是没有远程名称前缀的分支的名称。

一个例子:

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/foo
  remotes/origin/master
$ git checkout foo
Branch 'foo' set up to track remote branch 'foo' from 'origin'.
Switched to a new branch 'foo'
$ git branch -a
* foo
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/foo
  remotes/origin/master
$

您可以在3.5 Git Branching - Remote BranchesPro Git中了解有关远程分支的更多信息。

答案 1 :(得分:0)

尝试git branch -a列出所有分支(本地和远程)。

然后git checkout YOUR_REMOTE_NAME/YOUR_BRANCH_NAME,示例git checkout origin/dev