我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:
$ git branch
* master
我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?
$ git branch
* master
* staging
* etc...
我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:
$ git branch
* master
我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?
$ git branch
* master
* staging
* etc...
当前回答
我通常只使用以下命令:
git fetch origin
git checkout --track origin/remote-branch
略短的版本:
git fetch origin
git checkout -t origin/remote-branch
其他回答
要列出远程分支,请执行以下操作:
git branch -r
要将远程分支签出为本地分支,请执行以下操作:
git checkout -b local_branch_name origin/remote_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 fetch && git checkout <branchname>
如何获取跟踪单个远程的所有Git分支。
这已经在Windows 10上的Red Hat和Git Bash上进行了测试和运行。
TLDR:
for branch in `git branch -r|grep -v ' -> '|cut -d"/" -f2`; do git checkout $branch; git fetch; done;
说明:
一行程序检查,然后获取除HEAD之外的所有分支。
列出远程跟踪分支。
git branch -r
忽略HEAD。
grep -v ' -> '
删除远程的分支名称。
cut -d"/" -f2
签出跟踪单个远程的所有分支。
git checkout $branch
提取已签出的分支。
git fetch
从技术上讲,新的本地分支不需要获取。
这可以用于获取或拉取新的分支,这些分支在远程中都有更改。
只需确保只有在准备合并时才进行拉。
测试设置
使用SSH URL检查存储库。
git clone git@repository.git
之前
检查本地分支机构。
$ git branch
* master
执行命令
执行一行。
for branch in `git branch -r|grep -v ' -> '|cut -d"/" -f2`; do git checkout $branch; git fetch; done;
之后
检查本地分支是否包括远程分支。
$ git branch
cicd
master
* preprod
玩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