10

I cannot remove origin/master from my server. No idea why.

Screenshot of my terminal

The error message is the following

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/master
To acanzian@elab.ecn.purdue.edu:/export/home/a/elabshare/git/ID-check.git
 ! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to 'acanzian@elab.ecn.purdue.edu:/export/home/a/elabshare/git/ID-check.git'

No, I am not using Github.

  • 1
    Why would you want to do that? Are there other branches? – Daniel B Apr 30 '14 at 16:14
  • Indeed there are other branches (check the link to the image, actually, could you display it for me, please?). We had to rebase master, and we did it on a temporal branch which now should become master. The only problem is that I don't know why I cannot kill master on the server. – Atcold May 1 '14 at 20:53
  • 2
    Maybe not the answer you're looking for, but you could force-push the rebased master to origin/master, effectively replacing the old one with the new one. – SlightlyCuban May 1 '14 at 21:28
  • In addition to the error message, please post the command you're using. – Kyralessa May 1 '14 at 22:51
  • @Kyralessa, check the screenshot. – Atcold May 3 '14 at 16:58
7

Fun fact: even remote repositories are on a branch. You're getting rejected because you're trying to delete the branch that your origin has currently "checked out".

If you have direct access to the repo, you can just open up a shell bare repor directory and use good old git branch to see what branch origin is currently on. To change it to another branch, you have to use git symbolic-ref HEAD refs/heads/another-branch.

If you are using a service like Github or Gitorious, you're going to have to use the UI the tool provides you to make the change (see this answer for how to do that in common tools).

  • Awesome, it worked and it gave me the chance of learning more about refs in Git! Thank you very much! (Yeah, I knew about how to deal with it on Github, but not on our personal server.) – Atcold May 3 '14 at 18:10
12

In lieu of actually removing master from the server, you can replace it like this:

git push origin otherbranch:master -f

That will replace master with the contents of otherbranch, but it'll still be called master on the remote. And then you can check out master as master in your local.

  • OK, thanks! I know I can force stuff, but I was wondering exactly why I couldn't remove the master branch, and the accepted answer explains why. – Atcold May 4 '14 at 20:51
  • 1
    +1. This was the only way I could delete a bad first commit on remotes/origin/master. – ctn May 26 '15 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.