How to fetch all Git branches

后端 未结 30 1627
情书的邮戳
情书的邮戳 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:58

    |‾‾‾‾‾‾‾‾‾‾‾‾‾fetch/clone‾‾‾‾‾‾‾‾‾‾‾‾↓   |‾‾‾‾‾‾‾‾‾‾‾‾checkout‾‾‾‾‾‾‾‾‾‾↓   
    |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾pull‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾↓
    Remote repository (`origin`) <=> Local repository <=> Index <=> Workspace
    ↑_________________push_______________|   ↑____commit____|  ↑____add_____| 
    
    
    # 拉取远程仓库所有分支信息 → 本地仓库
    # fetch all remote repository branch meta → local repository
    git remote set-branches origin '*'
    git fetch -v
    
    # 把所有远程分支数据搞到本地
    # fetch all remote repository branch data → local repository
    git branch -r | grep -v '\->' | while read remote; do git branch "${remote#origin/}" "$remote"; done
    git fetch --all
    git pull --all
    

提交回复
热议问题