我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:
$ git branch
* master
我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?
$ git branch
* master
* staging
* etc...
我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:
$ git branch
* master
我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?
$ git branch
* master
* staging
* etc...
当前回答
玩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 remote update
$ git pull --all
这假设所有分支都被跟踪。
如果他们不是,你可以在Bash中发射这个:
for remote in `git branch -r `; do git branch --track $remote; done
然后运行命令。
注意:请阅读下面的警告注释。
设置别名:(基于顶部答案)
git config --global alias.track-all-branches '!git fetch --all && for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done && git fetch --all'
现在要跟踪所有分支:
git跟踪所有分支
克隆主存储库后,您只需执行
git fetch && git checkout <branchname>
git remote add origin https://yourBitbucketLink
git fetch origin
git checkout -b yourNewLocalBranchName origin/requiredRemoteBranch (use tab :D)
现在本地您的NewLocalBranchName是您所需的RemoteBranch。
确保所有远程分支都可以在.git/config文件中获取。
在本例中,只有原始/生产分支是可获取的,即使您尝试执行git fetch,除了获取生产分支之外,一切都不会发生:
[origin]
fetch = +refs/heads/production:refs/remotes/origin/production
该行应替换为:
[origin]
fetch = +refs/heads/*:refs/remotes/origin/*
然后运行git fetch等。。。