How to clone all remote branches in Git?

后端 未结 30 2133
情话喂你
情话喂你 2020-11-22 01:08

I have a master and a development branch, both pushed to GitHub. I\'ve cloned, pulled, and fetched, but I re

30条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 01:33

    I wrote this small Powershell functions to be able to checkout all my git branches, that are on origin remote.

    Function git-GetAllRemoteBranches {
         iex "git branch -r"                       <# get all remote branches #> `
         | % { $_ -Match "origin\/(?'name'\S+)" }  <# select only names of the branches #> `
         | % { Out-Null; $matches['name'] }        <# write does names #>
    }
    
    
    Function git-CheckoutAllBranches {
        git-GetAllRemoteBranches `
            | % { iex "git checkout $_" }          <# execute ' git checkout ' #>
    }
    

    More git functions can be found on my git settings repo

提交回复
热议问题