git 查看、建立、刪除 本地,遠程 分支

1. 查看遠程分支

git branch -r
origin/master

2. 查看本地分支

git branch 
*master

:以*開頭指明如今所在的本地分支git

3. 查看本地分支和遠程分支

git branch -a
*master
remotes/origin/master

4. 建立分支

*新建一個分支,但依然停留在當前分支spa

git branch [branch-name]code

*新建一個分支,並切換到該分支上blog

git branch -b [branch-name]rem

4-1 建立本地分支it

$ git branch test_1

$ git branch -a
* master
  test_1
  remotes/origin/master

:建立本地分支時,默認是把所在的本地分支的東西拷貝給新建本地的分支。ast

4-2 把本地分支推送到遠端做爲遠端分支class

$ git push origin test_1
To git@******
 * [new branch]      test_1 -> test_1

$ git branch -a
* master
  test_1
  remotes/origin/master
  remotes/origin/test_1

:git push origin test_1會把本地的test_1分支推送到遠端,本地test_1分支和遠端的對應關係是test_1-->test_1test

若是本地根本沒有分支test_9,推送的話會提示錯誤推送

5. 切換到分支

$ git checkout test_1
Switched to branch 'test_1'

6. 刪除本地分支

$ git branch -a
  master
  test_1
  test_2
  remotes/origin/master
  remotes/origin/test_1
  remotes/origin/test_2

$ git branch -d test_2
Deleted branch test_2 (was c470057).

$git branch -a
  master
  test_1
  remotes/origin/master
  remotes/origin/test_1
  remotes/origin/test_2

能夠看到本地分支test_2刪除了

7. 刪除遠程分支

$ git branch -a
* master
  test_1
  remotes/origin/master
  remotes/origin/test_1
  remotes/origin/test_2

$ git push origin :test_2
To git@*********- [deleted]         test_2

$ git branch -a
* master
  test_1
  remotes/origin/master
  remotes/origin/test_1

:git push origin :*** 就是刪除遠程分支的意思,和剛纔我刪除本地無關。以下面,我留着本地test_1分支,只是刪除了遠端的分支test_1

$ git push origin :test_1
To git@********
 - [deleted]         test_1

$ git branch -a
* master
  test_1
  remotes/origin/master
相關文章
相關標籤/搜索