使用Git時(shí)會(huì)有很多分支辟狈,本文專指遠(yuǎn)程庫新建了一個(gè)分支,本地庫需要同步分支夏跷。
1.查看遠(yuǎn)程分支-—— git branch -a
在項(xiàng)目目錄下操作哼转,需要切換的是auto
git branch -b 切換遠(yuǎn)程分支
使用
git branch -a
后發(fā)現(xiàn)沒有auto
分支,去gitlab看了下gitlab上遠(yuǎn)程分支
于是找了下原因:
git branch -a
:列出本地分支和遠(yuǎn)程分支槽华,這里的遠(yuǎn)程分支指的是本地保存的遠(yuǎn)程跟蹤分支壹蔓,auto
是新建分支,不在跟蹤范圍內(nèi)硼莽,使用git fetch
將本地跟蹤的遠(yuǎn)程分支進(jìn)行更新庶溶,與遠(yuǎn)程庫一致。
git fetch
2.查看本地分支- git branch
$ git branch
master
* new
3.切換分支 - git checkout
本地切換分支用git checkout
懂鸵,切換遠(yuǎn)程分支如下:
git checkout -b
在切換回
new
分支
$ git checkout new
Switched to branch 'new'
Your branch is up-to-date with 'origin/new'.