How to clone all remote branches in Git?

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

    You can easily switch to a branch without using the fancy "git checkout -b somebranch origin/somebranch" syntax. You can do:

    git checkout somebranch
    

    Git will automatically do the right thing:

    $ git checkout somebranch
    Branch somebranch set up to track remote branch somebranch from origin.
    Switched to a new branch 'somebranch'
    

    Git will check whether a branch with the same name exists in exactly one remote, and if it does, it tracks it the same way as if you had explicitly specified that it's a remote branch. From the git-checkout man page of Git 1.8.2.1:

    If is not found but there does exist a tracking branch in exactly one remote (call it ) with a matching name, treat as equivalent to

    $ git checkout -b  --track /
    

提交回复
热议问题