1. 程式人生 > >無法刪除git遠端分支的問題

無法刪除git遠端分支的問題

當刪除遠端分支時,可能會出錯以下的錯誤:

$ git push origin :alpha
remote: error: By default, deleting the current branch is denied, because the next
remote: error: 'git clone' won't result in any file checked out, causing confusion.
remote: error:
remote: error: You can set 'receive.denyDeleteCurrent' configuration variable to
remote: error: 'warn' or 'ignore' in the remote repository to allow deleting the
remote: error: current branch, with or without a warning message.
remote: error:
remote: error: To squelch this message, you can set it to 'refuse'.
remote: error: refusing to delete the current branch: refs/heads/alpha
To remote_repository_uri.git
! [remote rejected] alpha (deletion of the current branch prohibited)
error: failed to push some refs to 'remote_repository_uri.git'

原因好像是因為HEAD指向了要刪除的分支。

解決方法有兩個:

1,修改HEAD的指向

http://www.drkdidel.be/en/blog/84/git-refusing-to-delete-a-remote-branch-because-it-is-set-as-current

2,修改git的配置

(沒具體試過,但上面的錯誤資訊來說,如果刪除的話,可能導致git clone命令無法check out出文件,

    所以感覺還是方法1好一些)

http://blog.csdn.net/sunalongl/article/details/52013435