How to fetch all Git branches

后端 未结 30 1018
情书的邮戳
情书的邮戳 2020-11-22 09:38

I cloned a Git repository, which contains about five branches. However, when I do git branch I only see one of them:

$ git branch
* master
         


        
30条回答
  •  孤街浪徒
    2020-11-22 09:59

    For Windows users using PowerShell:

    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
    

提交回复
热议问题