程序员

Git 快速使用 之 Git 分支 branch

2017-08-15  本文已影响47人  mm_cuckoo

查看分支

git 命令: $ git branch -a

说明:查看所有分支

cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev_1
  remotes/origin/dev_org
  remotes/origin/master

* 代表当前处在的分支,

切换分支

git 命令: $ git checkout dev

说明:切换到dev 分支上

cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git checkout dev
M   app/src/main/res/values/colors.xml
Switched to branch 'dev'
Your branch is up-to-date with 'origin/dev'.
cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch -a
* dev
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev_1
  remotes/origin/dev_org
  remotes/origin/master
cfox@cfox-PC:~/Disk/gitTest/NDKLearn$ 

说明:M app/src/main/res/values/colors.xml 这条信息是告诉我们这个文件被我们修改了,但没有提交,会在该分支中体现

创建分支

git 命令: $ git branch new_branch

说明:创建新的名为 new_branch 分支

cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch new_branch
cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch -a
* dev
  master
  new_branch
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev_1
  remotes/origin/dev_org
  remotes/origin/master

删除分支

git 命令: $ git branch -d new_branch

说明:删除名为 new_branch 的分支

cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch -d new_branch 
Deleted branch new_branch (was e4f191e).
cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch -a
* dev
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev_1
  remotes/origin/dev_org
  remotes/origin/master

将分支推到远程

git 命令 :$ git push origin new_branch

说明:将分支 new_branch 推送到远程

cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch new_branch
cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch -a
* dev
  master
  new_branch
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev_1
  remotes/origin/dev_org
  remotes/origin/master
cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git push origin new_branch 
Total 0 (delta 0), reused 0 (delta 0)
To github.com:CNCFOX/NDKLearn.git
 * [new branch]      new_barnch -> new_branch
cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch -a
* dev
  master
  new_branch
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev_1
  remotes/origin/dev_org
  remotes/origin/master
  remotes/origin/new_branch

删除远程分支

git 命令: $ git branch -r -d origin/new_barnch

说明: 删除远程跟踪分支 origin/new_barnch

git 命令: $ git push origin :new_barnch

说明: 将删除动作同步到远程

cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch -a
* dev
  master
  new_barnch
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev_1
  remotes/origin/dev_org
  remotes/origin/master
  remotes/origin/new_barnch
cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch -d new_barnch 
Deleted branch new_branch (was e4f191e).
cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch -a
* dev
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev_1
  remotes/origin/dev_org
  remotes/origin/master
  remotes/origin/new_barnch
cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch -r -d origin/new_barnch 
Deleted remote-tracking branch origin/new_branch (was adb7752).
cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git branch -a
* dev
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/dev_1
  remotes/origin/dev_org
  remotes/origin/master
cfox@cfox-PC:~/Disk/gitTest/NDKLearn
$ git push origin :new_barnch 
To github.com:CNCFOX/NDKLearn.git
 - [deleted]         new_barnch

上一篇下一篇

猜你喜欢

热点阅读