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

17 篇文章 1 订阅
8 篇文章 1 订阅

分支操作

删除本地分支

命令:

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

20240117更新:推荐使用新的命令格式
 git push origin --delete master_bak 

实战:

$ 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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值