3

假设 repo at$REPO_URL多个分支,包括一个名为dev. 现在,假设我一个接一个地运行以下命令

% git clone $REPO_URL --branch dev wd
% cd wd
% git branch -a
* dev
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/issue6
  remotes/origin/issue26
  remotes/origin/issue30
  ...
  remotes/origin/issue709
  remotes/origin/issue712
  remotes/origin/issue716
  remotes/origin/master

此时我必须做什么,以便表单的每个分支都有一个与其完全匹配remotes/origin/X的本地分支?X我的意思是以下两个命令将产生相同的输出:

% git rev-parse remotes/origin/X
% git rev-parse X

并且输出git branch -a最终看起来像这样:

* dev
  issue6
  issue26
  issue30
  ...
  issue709
  issue712
  issue716
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/issue6
  remotes/origin/issue26
  remotes/origin/issue30
  ...
  remotes/origin/issue709
  remotes/origin/issue712
  remotes/origin/issue716
  remotes/origin/master
4

2 回答 2

3

您不需要这样做fetch,因为您在克隆存储库时已经这样做了。你想要的是一个本地分支来匹配每个远程跟踪分支,为此你可以使用checkout

git checkout -b issue6 origin/issue6

所以你可以有一个脚本循环遍历所有远程分支并检查它们。

正如评论中提到的,最新版本的 git 可以使用更简单的命令:

git checkout issue6
于 2013-03-07T19:48:21.450 回答
2

一个外壳 for 循环将做到这一点:

for BRANCH in $(git branch -r | grep -v HEAD) # list of remote branches (excluding HEAD)
do
    git checkout --track ${BRANCH}
done
于 2013-03-07T19:49:20.230 回答