You can fetch all branches from all remotes like this:
(您可以从所有遥控器中获取所有分支,如下所示:)
git fetch --all
It's basically a power move .
(这基本上是一种权力移动 。)
fetch
updates local copies of remote branches so this is always safe for your local branches BUT :
(fetch
更新远程分支的本地副本,因此这对于您的本地分支来说总是安全的但是 :)
fetch
will not update local branches (which track remote branches);
(fetch
不会更新本地分支( 跟踪远程分支);)
if you want to update your local branches you still need to pull every branch. (如果你想更新你的本地分支,你仍然需要拉每个分支。)
fetch
will not create local branches (which track remote branches), you have to do this manually.
(fetch
不会创建本地分支( 跟踪远程分支),您必须手动执行此操作。)
If you want to list all remote branches: git branch -a
(如果要列出所有远程分支: git branch -a
)
To update local branches which track remote branches:
(更新跟踪远程分支的本地分支:)
git pull --all
However, this can be still insufficient.
(但是,这仍然不够。)
It will work only for your local branches which track remote branches. (它仅适用于跟踪远程分支的本地分支。)
To track all remote branches execute this oneliner BEFORE git pull --all
: (要跟踪所有远程分支,请执行此oneliner BEFORE git pull --all
:)
git branch -r | grep -v '->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
TL;DR version (TL; DR版本)
git branch -r | grep -v '->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
(It seems that pull fetches all branches from all remotes, but I always fetch first just to be sure.)
((看起来拉取所有遥控器的所有分支,但我总是首先获取以确定。))
Run the first command only if there are remote branches on the server that aren't tracked by your local branches.
(仅当服务器上存在未由本地分支跟踪的远程分支时,才运行第一个命令。)
PS AFAIK git fetch --all
and git remote update
are equivalent.
(PS AFAIK git fetch --all
和git remote update
是等效的。)
Kamil Szot's comment , which folks have found useful.
(卡米尔索佐的评论 ,人们发现有用。)
I had to use:
(我不得不使用:)
for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done
because your code created local branches named origin/branchname
and I was getting "refname 'origin/branchname' is ambiguous whenever I referred to it.
(因为你的代码创建了名为origin/branchname
本地分支,而且每当我提到它时,我得到的“refname”origin / branchname'都是模棱两可的。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…