Git基础操作:删除本地分支、删除远程分支、创建本地分支

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hl_java/article/details/82896352

分支操作

删除本地分支

命令:

git branch -d develop

实战:

$ git branch -d develop
error: Cannot delete branch 'develop' checked out at '/Users/xxx/work/git/xxx-server'
$ git checkout feature/gantt20180830
Switched to branch 'feature/gantt20180830'
Your branch is up to date with 'origin/feature/gantt20180830'.
$ git branch -a
  develop
  feature/20180620issuearchive
* feature/gantt20180830
  feature/refactor_finish
  master
  testing
  remotes/origin/HEAD -> origin/master
  remotes/origin/customer_field_cache
  remotes/origin/develop
  remotes/origin/es_search
$ git branch -d develop
warning: deleting branch 'develop' that has been merged to
         'refs/remotes/origin/develop', but not yet merged to HEAD.
Deleted branch develop (was 4a47bd100).
$ git branch -a
  feature/20180620issuearchive
* feature/gantt20180830
  feature/refactor_finish
  master
  testing
  remotes/origin/HEAD -> origin/master
  remotes/origin/customer_field_cache
  remotes/origin/develop
  remotes/origin/es_search

可以看到已经删除掉本地分支develop了,总结一下就是删除前本地分支不能是即将要删除的分支

删除远程分支

命令:

git push origin :hotfix/movebug20180629

实战:

$ git branch -a
* develop
  feature/20180620issuearchive
  feature/gantt20180830
  feature/refactor_finish
  master
  remotes/origin/hotfix/listMove
  remotes/origin/hotfix/listcopy20180115
  remotes/origin/hotfix/movebug20180629
  remotes/origin/hotfix/newFunction-20180130
  remotes/origin/hotfix/relation_search
 
$  git push origin :hotfix/movebug20180629
remote: delete branch, skip check...
remote: run code_review post hook success
To http://git.xiaojukeji.com/lean/lean-server.git
 - [deleted]             hotfix/movebug20180629

$ git branch -a
* develop
  feature/20180620issuearchive
  feature/gantt20180830
  feature/refactor_finish
  master
  testing
  remotes/origin/hotfix/listMove
  remotes/origin/hotfix/listcopy20180115
  remotes/origin/hotfix/newFunction-20180130
  remotes/origin/hotfix/relation_search 

在这个命令git push origin :hotfix/movebug20180629当中,你需要注意的是 (注意origin后面有一个空格)

创建本地分支,并切换到这个新建的本地分支

命令:

git checkout -b develop

实战

$ git branch -a
  feature/20180620issuearchive
* feature/gantt20180830
  feature/refactor_finish
  master
  testing
  remotes/origin/HEAD -> origin/master
  remotes/origin/customer_field_cache
  remotes/origin/develop
  remotes/origin/es_search
$ git checkout -b develop
Switched to a new branch 'develop'
$ git branch -a
* develop
  feature/20180620issuearchive
  feature/gantt20180830
  feature/refactor_finish
  master
  testing
  remotes/origin/HEAD -> origin/master
  remotes/origin/customer_field_cache
  remotes/origin/develop
  remotes/origin/es_search

猜你喜欢

转载自blog.csdn.net/hl_java/article/details/82896352
今日推荐