尝试删除远程分支失败:
$ git branch -d remotes/origin/bugfix
error: branch 'remotes/origin/bugfix' not found.
$ git branch -d origin/bugfix
error: branch 'origin/bugfix' not found.
$ git branch -rd origin/bugfix
Deleted remote branch origin/bugfix (was 2a14ef7).
$ git push
Everything up-to-date
$ git pull
From github.com:gituser/gitproject
* [new branch] bugfix -> origin/bugfix
Already up-to-date.
如何在本地和远程正确删除 remotes/origin/bugfix
分支?
最佳答案
执行摘要
git push -d <remote_name> <branchname>
git branch -d <branchname>
注意:在大多数情况下,<remote_name>
将是 origin
.
删除本地分支
要删除本地 分支,请使用以下方法之一:
git branch -d <branch_name>
git branch -D <branch_name>
-d
option 是--delete
的别名,如果分支已经完全 merge 到其上游分支中,则仅删除该分支。-D
option 是--delete --force
的别名,删除分支“无论其 merge 状态如何。” [来源:man git-branch
]- 截至Git v2.3 ,
git branch -d
(删除)学会了兑现-f
(力)旗帜。 - 如果您尝试删除当前选定的分支,您将收到错误消息。
删除远程分支
截至Git v1.7.0 ,您可以使用
删除远程分支$ git push <remote_name> --delete <branch_name>
这可能比
更容易记住$ git push <remote_name> :<branch_name>
这是在 Git v1.5.0 中添加的“删除远程分支或标签。”
以 Git v2.8.0 开头, 你也可以使用 git push
与 -d
选项作为 --delete
的别名.因此,您安装的 Git 版本将决定您是否需要使用更简单或更难的语法。
删除远程分支 [2010 年 1 月 5 日的原始答案]
来自 Pro Git 的第 3 章|斯科特·查孔:
Deleting Remote Branches
Suppose you’re done with a remote branch — say, you and your collaborators are finished with a feature and have merged it into your remote’s main branch (or whatever branch your stable code-line is in). You can delete a remote branch using the rather obtuse syntax
git push [remotename] :[branch]
. If you want to delete your server-fix branch from the server, you run the following:
$ git push origin :serverfix
To git@github.com:schacon/simplegit.git
- [deleted] serverfix
Boom. No more branches on your server. You may want to dog-ear this page, because you’ll need that command, and you’ll likely forget the syntax. A way to remember this command is by recalling the
git push [remotename] [localbranch]:[remotebranch]
syntax that we went over a bit earlier. If you leave off the[localbranch]
portion, then you’re basically saying, “Take nothing on my side and make it be[remotebranch]
.”
我发布了git push origin: bugfix
而且效果很好。 Scott Chacon 是对的——我想要 dog ear该页面(或者通过在 Stack Overflow 上回答这个问题来虚拟地折耳)。
然后你应该在其他机器上执行这个
# Fetch changes from all remotes and locally delete
# remote deleted branches/tags etc
# --prune will do the job :-;
git fetch --all --prune
传播变化。
关于git - 如何在本地和远程删除 Git 分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37435884/