删除远程分支的尝试失败 :
$ 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.
我如何正确删除本地和远程的远程/原产/bugfix分支?
如果您想要用一个命令来完成这两个步骤, 您可以在 ~ /. gitconfig 中添加下面的替代名称 :
[alias]
rmbranch = "!f(){ git branch -d ${1} && git push origin --delete ${1}; };f"
或者,您可以从命令行使用
git config --global alias.rmbranch \
'!f(){ git branch -d ${1} && git push origin --delete ${1}; };f'
注:如果使用 -d(小写d),该分支只有在合并时才被删除。要强制删除,您需要使用 -D(大写D)。
这是所有其他答案的拼图。 它需要 Ruby 1.9. 3 +, 并且只在 OS X 上测试 。
调用此文件 git- remove, 让它可执行, 并把它放在您的路径中。 然后使用, 例如, git 删除临时 。
#!/usr/bin/env ruby
require 'io/console'
if __FILE__ == $0
branch_name = ARGV[0] if (ARGV[0])
print "Press Y to force delete local and remote branch #{branch_name}..."
response = STDIN.getch
if ['Y', 'y', 'yes'].include?(response)
puts "\nContinuing."
`git branch -D #{branch_name}`
`git branch -D -r origin/#{branch_name}`
`git push origin --delete #{branch_name}`
else
puts "\nQuitting."
end
end