How to fetch all Git branches

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

    You can fetch all the branches by:

    git fetch --all
    

    or:

    git fetch origin --depth=10000 $(git ls-remote -h -t origin)
    

    The --depth=10000 parameter may help if you've shallowed repository.


    To pull all the branches, use:

    git pull --all
    

    If above won't work, then precede the above command with:

    git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
    

    as the remote.origin.fetch could support only a specific branch while fetching, especially when you cloned your repo with --single-branch. Check this by: git config remote.origin.fetch.

    After that you should be able to checkout any branch.

    See also:

    • How to fetch all remote branches?
    • How to clone all remote branches in Git?

    To push all the branches to the remote, use:

    git push --all
    

    eventually --mirror to mirror all refs.


    If your goal is to duplicate a repository, see: Duplicating a repository article at GitHub.

提交回复
热议问题