如果是大家一起协作的情况,可能其他人推了其他分支到中央仓库,这时候你本地是看不到的。
比如原来只有master分支,另外一个人推送了f1分支。
这时候在你的本地,
λ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
直接执行切换分支到f1,
λ git checkout f1
error: pathspec 'f1' did not match any file(s) known to git.
当然是不行的啦。
那么应该怎么做呢?
你可以把中央的分支信息取下来
λ git fetch origin
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://git.coding.net/xxx/xxx
* [new branch] f1 -> origin/f1
λ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/f1
remotes/origin/master
这样你就能愉快地切换分支了
λ git checkout f1
Branch f1 set up to track remote branch f1 from origin.
Switched to a new branch 'f1'
此时你已经在f1分支了,
λ git branch -a
* f1
master
remotes/origin/HEAD -> origin/master
remotes/origin/f1
remotes/origin/master
*在前面表示本地当前所指向的分支。