git 查看、创建、切换、删除、重命名和推送分支

1、查看本地所有分支:前面有 “*” 的是当前所处的分支 

$ git branch
  test-A
* test-B

 

2、查看本地和远程服务器的所有分支:

$ git branch -a
  test-A
* test-B
  remotes/origin/HEAD -> origin/test-C  // 表示远程服务器的当前分支,新clone代码会默认在此分支
  remotes/origin/test-D

 

3、创建本地分支

$ git branch test-E
$ git branch
  test-A
* test-B
  test-E

 

4、切换本地分支

$ git checkout test-E
$ git branch
  test-A
  test-B
* test-E

 

5、创建并切换分支(等同于以上的 3、4)

$ git checkout -b test-E

 

6、删除本地分支

$ git branch -D test-A
Deleted branch test-A (was xxxxxxx).

 

7、重命名本地分支

$ git branch -m test-E test-F
$ git branch
* test-B
  test-F

 

8、本地分支推送到远程服务器

$ git push origin test-F:test-F

 

7、删除远程分支

$ git branch -r -d origin/test-F 
已删除远程分支 origin/test-F(曾为 88ffe37)。
$ git push origin :test-F
To xxx@192.168.1.100:xxx.git
 - [deleted]         test-F

 删除远程分支后,git branch -a 还是能看到刚才删除的分支。

$ git branch -a
* test-B
  test-F
  remotes/origin/test-A
  remotes/origin/test-B
  remotes/origin/HEAD -> origin/test-C
  remotes/origin/test-D
  remotes/origin/test-F

$ git remote show origin
  refs/remotes/origin/test-F stale (use 'git remote prune' to remove)

$ git remote prune origin
Pruning origin
* [pruned] origin/test-F

$ git branch -a
* test-B
  test-F
  remotes/origin/test-A
  remotes/origin/test-B
  remotes/origin/HEAD -> origin/test-C
  remotes/origin/test-D

 

posted @ 2017-12-13 14:19  LeeAaron  阅读(872)  评论(0编辑  收藏  举报