每当我在远程仓库中创建一个新分支时,我都无法将其转移到我的本地仓库。
我试过了:
git fetch --all
,它实际更新了远程分支,但它们没有显示git branch
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
是唯一对我有用的东西,但它会抓取远程所有分支。在大型项目中,我最终从git branch
答案 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 Branches的Pro Git中了解有关远程分支的更多信息。
答案 1 :(得分:0)
尝试git branch -a
列出所有分支(本地和远程)。
然后git checkout YOUR_REMOTE_NAME/YOUR_BRANCH_NAME
,示例git checkout origin/dev