Recently when I wanted to rename my git master branch (using grb rename), I encountered this error in the step when grb deletes the master branch in the server.
git push origin :refs/heads/master
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: 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: To squelch this message, you can set it to ‘refuse’.
remote: error: refusing to delete the current branch: refs/heads/master
A quick search revealed that it is not possible to do the rename, at least without getting into some trouble! So here’s what I did as a work around to rename the master branch.
There is a file “HEAD” located in the git repository containing the line: ref: refs/heads/master. This is apparently the branch to pick whenever the repository is cloned.
Changing this line to point to another branch and cloning the repo proved my guess right. Now, I went ahead with the rename using grb again and this time it went through successfully. Of course, I went and changed the “HEAD” file back to it’s original as I had another branch renamed to master.