git-fetch 命令从远程仓库复制 heads 和 tags 信息到本地,保存在临时文件 .git/FETCH_HEAD 中以备 git-merge 命令使用。git
你能够使用 git fetch
命令获取远程仓库全部分支信息,或者 git fetch --all
或 git remote update
命令获取全部远程仓库全部分支信息。shell
使用 fetch 命令只会更新保存在本地的远程分支信息,对本地分支不会有任何操做,所以运行该命令老是安全的。安全
你也能够使用 git pull --all
命令拉取并合并远程分支,但这仅限于本地已经存在的分支。fetch
要追踪全部远程分支,能够使用如下命令:code
for remote in $(git branch -r); do git branch --track $remote; done
以上代码是一个简单的 shell 循环语句,意思是设置远程追踪的本地分支。rem
而后再使用 git pull --all
命令更新每个本地分支。get
Ref.: How to fetch all git branchesit