当前位置:   article > 正文

Git基础操作:删除本地分支、删除远程分支、创建本地分支_cannot delete branch 'master-guotaicai-ljj-lingshi

cannot delete branch 'master-guotaicai-ljj-lingshi' used by worktree at 'c:/

分支操作

删除本地分支

命令:

git branch -d develop
  • 1

实战:

$ 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

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

删除远程分支

命令:

git push origin :hotfix/movebug20180629

20240117更新:推荐使用新的命令格式
 git push origin --delete master_bak 
  • 1
  • 2
  • 3
  • 4

实战:

$ 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 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

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

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

命令:

git checkout -b develop
  • 1

实战

$ 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/550291
推荐阅读
相关标签
  

闽ICP备14008679号