git 删除本地分支/远程分支

Posted 在奋斗的大道

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git 删除本地分支/远程分支相关的知识,希望对你有一定的参考价值。

Git 删除本地分支指令:

# 语法
git branch -d 本地分支名称

# 实例
$ git branch -d zzg-mastr

Git 删除远程分支指令:

# 语法
git push origin --delete 远程分支名称

# 实例
git push origin --delete main

 Git Bash 控制台:

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ git branch -a
* master
  remotes/origin/main
  remotes/origin/master

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ git push origin --delete main
To github.com:zhouzhiwengang/SpringBoot-Project.git
 - [deleted]         main

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ git branch -a
* master
  remotes/origin/master

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ git checkout -b zzg-mastr origin/master
Switched to a new branch 'zzg-mastr'
M       SmartOA/.idea/vcs.xml
A       SmartUrban/.idea/vcs.xml
branch 'zzg-mastr' set up to track 'origin/master'.

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (zzg-mastr)
$ git branch -D zzg-master
error: branch 'zzg-master' not found.

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (zzg-mastr)
$ git branch -D zzg-mastr
error: Cannot delete branch 'zzg-mastr' checked out at 'E:/idea_workspace'

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (zzg-mastr)
$ git branch -a
  master
* zzg-mastr
  remotes/origin/master

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (zzg-mastr)
$ git branch -D zzg-mastr
error: Cannot delete branch 'zzg-mastr' checked out at 'E:/idea_workspace'

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (zzg-mastr)
$ git checkout master
Switched to branch 'master'
M       SmartOA/.idea/vcs.xml
A       SmartUrban/.idea/vcs.xml
Your branch is up to date with 'origin/master'.

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace (master)
$ git branch -d zzg-mastr
Deleted branch zzg-mastr (was 75ffb6e).

以上是关于git 删除本地分支/远程分支的主要内容,如果未能解决你的问题,请参考以下文章

Git 如何删除本地分支和远程分支

git操作:查看分支删除本地分支和远程分支

git 查看远程分支本地分支创建分支把分支推到远程repository删除本地分支

Git 中删除本地分支和删除远程分支是两回事儿

Git 中删除本地分支和删除远程分支是两回事儿

删除本地git的远程分支和远程删除git服务器的分支