We are running Gerrit and on our server we were trying to delete the ‘master’ branch since we no longer use it as the main stream. In fact, we don’t want people pushing to it so we decided to delete it. Then we got the following:
To ssh://git:29418/MyRepo
! [remote rejected] master (branch is currently checked out)
error: failed to push some refs to ‘ssh://git:29418/MyRepo’
The branch is currently checked out!? It doesn’t sound like a gerrit failure. Must be Git.
Thinking through, it’s a bare repository – how could the branch be checked out. Then I logged onto the machine and did ‘git branch’:
* master
otherBranch
Sure enough the master is set as the HEAD.
This means we need to update HEAD to another branch. Running the following command is necessary:
git symbolic-ref HEAD refs/heads/otherBranch
Now we look after running ‘git branch’
master
* otherBranch
Perfect! The symbolic-ref command successfully updated the bare repo to be looking at another branch as it’s HEAD!
Hope that helps someone.