Transferred from: http://www.barretlee.com/blog/2014/04/30/switch-branch-in-git/
Remote repository git clone down and when you execute GIT branch, you'll only see
* master
Do not see other branches, even if there are other branches on the remote repository, use the
git branch -va
You can view the local + remote branches list
master 0840594 merge master and 1.0.0remotes/origin/1.0.0 743012a ‘update‘remotes/origin/2.0.0 2787838 udpateremotes/origin/HEAD -> origin/masterremotes/origin/master 0840594 merge master and 1.0.0
If you want to switch to origin/2.0.0 's branch, we can
git branch remotes/origin/2.0.0
But the result is not satisfactory:
* (detached from origin/2.0.0)master
Git branch will see the above information, and here's one more step:
2.0.0
-B means base, with the current branch as base, and a new branch named 2.0.0, which of course can also use other names. At this point, you can see the following GIT branch:
$ git br master* 2.0.0
It's OK.
The most straightforward approach is to:
git checkout -t origin/2.0.0
Ability to create a new local branch and extract the remote branch directly.
git switches to remote branch