How to fetch all Git branches

后端 未结 30 1015
情书的邮戳
情书的邮戳 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
    git remote add origin https://yourBitbucketLink
    
    git fetch origin
    
    git checkout -b yourNewLocalBranchName origin/requiredRemoteBranch (use tab :D)
    

    Now locally your yourNewLocalBranchName is your requiredRemoteBranch.

    0 讨论(0)
  • 2020-11-22 10:01

    I believe you have cloned the repository by:

    git clone https://github.com/pathOfrepository
    

    Now go to that folder using cd:

    cd pathOfrepository
    

    If you type git status you can see all:

       On branch master
    Your branch is up-to-date with 'origin/master'.
    nothing to commit, working directory clean
    

    To see all hidden branch types:

     git branch -a
    

    It will list all the remote branchs.

    Now if you want to checkout on any particular branch just type:

    git checkout -b localBranchName origin/RemteBranchName
    
    0 讨论(0)
  • 2020-11-22 10:01

    Have tried many ways, only this one is simple and works for me.

    for branch in $(git ls-remote -h git@<your_repository>.git | awk '{print $2}' | sed 's:refs/heads/::')
    do
      git checkout "$branch"
      git pull
    done
    
    0 讨论(0)
  • 2020-11-22 10:02

    If you do:

    git fetch origin
    

    then they will be all there locally. If you then perform:

    git branch -a
    

    you'll see them listed as remotes/origin/branch-name. Since they are there locally you can do whatever you please with them. For example:

    git diff origin/branch-name 
    

    or

    git merge origin/branch-name
    

    or

    git checkout -b some-branch origin/branch-name
    
    0 讨论(0)
  • 2020-11-22 10:03

    After you clone the master repository, you just can execute

    git fetch && git checkout <branchname>
    
    0 讨论(0)
  • 2020-11-22 10:07

    Make sure all the remote branches are fetchable in .git/config file.

    In this example, only the origin/production branch is fetchable, even if you try to do git fetch --all nothing will happen but fetching the production branch:

    [origin]
    fetch = +refs/heads/production:refs/remotes/origin/production
    

    This line should be replaced by:

    [origin]
    fetch = +refs/heads/*:refs/remotes/origin/*
    

    Then run git fetch etc...

    0 讨论(0)
提交回复
热议问题