How to clone all remote branches in Git?

后端 未结 30 2109
情话喂你
情话喂你 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:52

    Why you only see "master"

    git clone downloads all remote branches but still considers them "remote", even though the files are located in your new repository. There's one exception to this, which is that the cloning process creates a local branch called "master" from the remote branch called "master". By default, git branch only shows local branches, which is why you only see "master".

    git branch -a shows all branches, including remote branches.


    How to get local branches

    If you actually want to work on a branch, you'll probably want a "local" version of it. To simply create local branches from remote branches (without checking them out and thereby changing the contents of your working directory), you can do that like this:

    git branch branchone origin/branchone
    git branch branchtwo origin/branchtwo
    git branch branchthree origin/branchthree
    

    In this example, branchone is the name of a local branch you're creating based on origin/branchone; if you instead want to create local branches with different names, you can do this:

    git branch localbranchname origin/branchone
    

    Once you've created a local branch, you can see it with git branch (remember, you don't need -a to see local branches).

提交回复
热议问题