git 从远程仓库拉取所有分支 [英] git pull all branches from remote repository
问题描述
如何将所有远程分支拉到我自己的存储库中?
如果我输入:
git branch -a
我得到一长串分支,但如果我输入:
git 分支
我只看到其中的两个.
如何将 ALL 分支拉入我的本地列表?
我知道我能做到:
git checkout --track origin/branch-name
但这一次只提取并检查一个分支.有什么方法可以一次性完成所有工作,而无需一遍又一遍地运行 git checkout --track origin/branch-name 的繁琐工作?
<小时>ps.我尝试了以下命令,它们都没有使远程分支出现在我的 git branch 列表中:
git fetch --allgit远程更新git pull --all
我通常用来使所有内容都可见的命令 upstream 分支,并且跟踪它们在将所有远程 git 分支作为本地分支进行跟踪":
remote=origin ;对于`git branch -r 中的brname |grep $remote |grep -v master |grep -v 头 |awk '{gsub(/[^/]+//,"",$1);打印 $1}'`;做 git branch --set-upstream-to $remote/$brname $brname ;完毕
或者:
remote=origin ;对于`git branch -r 中的brname |grep $remote |grep -v master |grep -v 头 |awk '{gsub(/[^/]+//,"",$1);打印 $1}'`;做 git branch --track $brname $remote/$brname ;完毕
<块引用>
为了提高可读性:
remote=origin ;//把你想要的遥控器的名字放在这里对于 ` 中的 brnamegit 分支 -r |grep $remote |grep -v master |grep -v 头|awk '{gsub(/[^/]+//,"",$1);打印 $1}'`;做git branch --set-upstream-to $remote/$brname $brname;# 或者git branch --track $brname $remote/$brname ;完毕
第二个是用于创建新的本地分支跟踪远程分支.
How do I pull all of the remote branches to my own repository?
if I type:
git branch -a
I get a long list of branches, but if I type:
git branch
I see only 2 of them.
How do I pull ALL branches into my local list?
I know I can do:
git checkout --track origin/branch-name
but that pulls and checks out only one branch at a time. Any way to get it all done at once without that whole tedious work of running git checkout --track origin/branch-name over and over and over again?
ps. I tried following commands, none of them made remote branches appear in my git branch list:
git fetch --all
git remote update
git pull --all
The command I usually use to make all visible upstream branches, and tracking them is detailed in "Track all remote git branches as local branches":
remote=origin ; for brname in `git branch -r | grep $remote | grep -v master | grep -v HEAD | awk '{gsub(/[^/]+//,"",$1); print $1}'`; do git branch --set-upstream-to $remote/$brname $brname ; done
Or:
remote=origin ; for brname in `git branch -r | grep $remote | grep -v master | grep -v HEAD | awk '{gsub(/[^/]+//,"",$1); print $1}'`; do git branch --track $brname $remote/$brname ; done
For more readability:
remote=origin ; // put here the name of the remote you want
for brname in `
git branch -r | grep $remote | grep -v master | grep -v HEAD
| awk '{gsub(/[^/]+//,"",$1); print $1}'
`; do
git branch --set-upstream-to $remote/$brname $brname;
# or
git branch --track $brname $remote/$brname ;
done
The second one is for creating new local branches tracking remote branches.
这篇关于git 从远程仓库拉取所有分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!