Git refusing to delete a remote branch because it is set as current

I wanted to do some clean-up on a remote repository, which contained a lot of obsolete branches. But one of them returned the following error:

$ 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'

As this verbose message explains, I was trying to delete the branch named "alpha", which was set as the current branch on the remote repository.

It was an old branch untouched for several months and I don't know how it has been set to be the current branch instead of master. Since the remote is a bare repository, I could not execute the usual git checkout master command. The solution is to move HEAD, which is a symbolic link pointing to the current branch. To make that link point to the master branch, execute the following command on the remote server:

$ git symbolic-ref HEAD refs/heads/master

We can verify where HEAD is pointing to with the same git symbolic-ref command:

$ git symbolic-ref HEAD


git-symbolic-ref Manual Page

"Upgrade to Firefox" bannerSupport La Quadrature du Net!Soutenir FramasoftSupport the Gooseberry project, Blender Foundation's 5th Open Movie project