我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:
$ git branch
* master
我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?
$ git branch
* master
* staging
* etc...
我克隆了一个包含许多分支的Git存储库。然而,git分支仅显示一个:
$ git branch
* master
我如何在本地拉所有分支,所以当我执行git分支时,它会显示以下内容?
$ git branch
* master
* staging
* etc...
当前回答
对于使用PowerShell的Windows用户:
git branch -r | ForEach-Object {
# Skip default branch, this script assumes
# you already checked-out that branch when cloned the repo
if (-not ($_ -match " -> ")) {
$localBranch = ($_ -replace "^.*?/", "")
$remoteBranch = $_.Trim()
git branch --track "$localBranch" "$remoteBranch"
}
}; git fetch --all; git pull --all
其他回答
玩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 add origin https://yourBitbucketLink
git fetch origin
git checkout -b yourNewLocalBranchName origin/requiredRemoteBranch (use tab :D)
现在本地您的NewLocalBranchName是您所需的RemoteBranch。
$ git remote update
$ git pull --all
这假设所有分支都被跟踪。
如果他们不是,你可以在Bash中发射这个:
for remote in `git branch -r `; do git branch --track $remote; done
然后运行命令。
注意:请阅读下面的警告注释。
如果您这样做:
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
根据Learnath2的回答,下面是我在执行gitclone[…]并cd到创建的目录后所做的操作:
git branch-r | grep-v master | awk{print\$1}| sed的/^ origin\/\(.*\)$/\1&/'| xargs-n2 git checkout-b
为我工作,但我不知道它会为你工作。小心。