我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:

$ git branch
* master

我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?

$ git branch
* master
* staging
* etc...

当前回答

Bash for循环不适合我,但这正是我想要的。我的所有分支在本地镜像为相同的名称。

git checkout --detach
git fetch origin '+refs/heads/*:refs/heads/*'

请参见下面Mike DuPont的评论。我想我是在Jenkins服务器上做这件事的,这让它处于分离头部模式。

其他回答

玩git时要小心,循序渐进。

$ git remote update  //This will update your local
$ git branch -a      //This will list all the branches(After updating you can now 
see the new branch in the list)
$ git checkout your_branch_name

我通常只使用以下命令:

git fetch origin
git checkout --track origin/remote-branch

略短的版本:

git fetch origin
git checkout -t origin/remote-branch

您可以通过以下单行命令获取所有分支:

git fetch --all && git pull --all && git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done

只有这三个命令才能获得所有分支:

git clone --mirror repo.git  .git     (gets just .git  - bare repository)

git config --bool core.bare false

git reset --hard

循环似乎对我不起作用,我想忽略起源/主。这是对我有用的。

git branch -r | grep -v HEAD | awk -F'/' '{print $2 " " $1"/"$2}' | xargs -L 1 git branch -f --track

之后:

git fetch --all
git pull --all