执行摘要
git push -d <remote_name> <branchname>
git branch -d <branchname>
Note:在多数情况下,<remote_name>
将origin
.
删除本地分支
要删除local分支,使用以下选项之一:
git branch -d <branch_name>
git branch -D <branch_name>
- The
-d
选项是一个别名--delete
,仅当分支已完全合并到其上游分支时才会删除该分支。
- The
-D
选项是一个别名--delete --force
,这将删除分支“无论其合并状态如何”。 [来源:man git-branch
]
- As of Git v2.3 https://github.com/git/git/blob/master/Documentation/RelNotes/2.3.0.txt,
git branch -d
(删除)学会尊重-f
(强行)旗帜。
- 如果您尝试删除当前选定的分支,您将收到错误消息。
删除远程分支
As of git v1.7.0 https://github.com/gitster/git/blob/master/Documentation/RelNotes/1.7.0.txt,您可以删除一个remote分支使用
$ git push <remote_name> --delete <branch_name>
这可能比更容易记住
$ git push <remote_name> :<branch_name>
添加到git v1.5.0 https://github.com/gitster/git/blob/master/Documentation/RelNotes/1.5.0.txt“删除远程分支或标签。”
从...开始git v2.8.0 https://github.com/git/git/blob/master/Documentation/RelNotes/2.8.0.txt,您还可以使用git push
与-d
选项作为别名--delete
。因此,您安装的 Git 版本将决定您是否需要使用更简单的语法或更难的语法。
删除远程分支 [2010 年 1 月 5 日的原始答案]
从第 3 章开始Pro Git http://git-scm.com/book/en/Git-Branching-Remote-Branches作者:斯科特·查康:
删除远程分支
假设您已经完成了一个远程分支 - 比如说,您和您的协作者完成了一项功能并将其合并到远程的主分支(或您的稳定代码行所在的任何分支)中。您可以使用相当迟钝的语法删除远程分支git push [remotename] :[branch]
。如果您想删除您的serverfix
从服务器分支,您运行以下命令:
$ git push origin :serverfix
To [email protected] /cdn-cgi/l/email-protection:schacon/simplegit.git
- [deleted] serverfix
繁荣。您的服务器上不再有分支。您可能想要将此页面折角,因为您将需要该命令,并且您可能会忘记语法。记住该命令的一种方法是回忆git push [remotename] [localbranch]:[remotebranch]
我们之前讨论过的语法。如果你离开[localbranch]
部分,那么你基本上是在说,“不要拿走我这边的任何东西,让它成为[remotebranch]
.”
I ran git push origin :bugfix
,而且效果很好。斯科特·查康 (Scott Chacon) 是对的——我会想要dog-ear http://en.wiktionary.org/wiki/dogear#Verb该页面(或者在 Stack Overflow 上回答这个问题实际上是狗耳朵)。
最后,在其他机器上执行以下命令来传播更改:
# Fetch changes from all remotes and locally delete
# remote deleted branches/tags etc
# --prune will do the job :-;
git fetch --all --prune