我克隆了一个 Git 存储库,它包含大约五个分支。但是,当我做git branch我只看到其中一个: 
$ git branch
* master我知道我可以做git branch -a来查看所有分支,但是我如何在本地拉出所有分支,所以当我做git branch ,它会显示以下内容? 
$ git branch
* master
* staging
* etc...您可以从所有遥控器中获取一个分支,如下所示:
git fetch --all fetch更新远程分支的本地副本,因此这对于您的本地分支来说总是安全的但是 : 
 fetch不会更新本地分支( 跟踪远程分支); 如果你想更新你的本地分支,你仍然需要拉每个分支。 
 fetch不会创建本地分支( 跟踪远程分支),您必须手动执行此操作。如果要列出所有远程分支: git branch -a 
更新跟踪远程分支的本地分支:
git pull --all但是,这仍然不够。它仅适用于跟踪远程分支的本地分支。要跟踪所有远程分支,请执行此 oneliner BEFORE git pull --all : 
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; donegit branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all(看起来拉取所有遥控器的所有分支,但我总是首先获取以确定。)
仅当服务器上存在未由本地分支跟踪的远程分支时,才运行第一个命令。
 PS AFAIK git fetch --all和git remote update是等效的。 
Kamil Szot 的评论 ,74(至少)人发现有用。
我不得不使用:
for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done因为你的代码创建了名为
origin/branchname本地分支,而且每当我提到它时,我得到的 “refname”origin / branchname' 都是模棱两可的。
列出远程分支: 
 git branch -r 
您可以将它们作为本地分支机构查看: 
 git checkout -b LocalName origin/remotebranchname 
您将需要创建跟踪远程分支的本地分支。
假设您只有一个名为origin远程服务器,此代码段将为所有远程跟踪服务器创建本地分支: 
for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done之后, git fetch --all将更新远程分支的所有本地副本。 
此外, git pull --all将更新您的本地跟踪分支,但根据您的本地提交以及如何设置'merge'configure 选项,它可能会创建合并提交,快进或失败。