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

$ git branch
* master

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

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

当前回答

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

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

git config --bool core.bare false

git reset --hard

其他回答

要列出远程分支,请执行以下操作:

git branch -r

要将远程分支签出为本地分支,请执行以下操作:

git checkout -b local_branch_name origin/remote_branch_name

如果您这样做:

git fetch origin

然后他们都会在当地。如果随后执行以下操作:

git branch -a

您将看到它们列为remotes/origin/分支名称。因为他们在当地,你可以随心所欲地和他们在一起。例如:

git diff origin/branch-name 

or

git merge origin/branch-name

or

git checkout -b some-branch origin/branch-name

我相信您已经通过以下方式克隆了存储库:

git clone https://github.com/pathOfrepository

现在使用cd转到该文件夹:

cd pathOfrepository

如果键入gitstatus,您可以看到所有:

   On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

要查看所有隐藏的分支类型,请执行以下操作:

 git branch -a

它将列出所有远程分支。

现在,如果您想在任何特定分支上签出,只需键入:

git checkout -b localBranchName origin/RemteBranchName

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

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

git config --bool core.bare false

git reset --hard

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

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