17

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

No, I am not using Github.

9
  • 1
    Why would you want to do that? Are there other branches?
    – Daniel B
    Apr 30, 2014 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, 2014 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. May 1, 2014 at 21:28
  • In addition to the error message, please post the command you're using.
    – user9528
    May 1, 2014 at 22:51
  • @Kyralessa, check the screenshot.
    – Atcold
    May 3, 2014 at 16:58

2 Answers 2

18

Fun fact: even remote, bare 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, filesystem-access to the repo:

  1. You can just open up a shell to the bare repo directory and use good old git branch to see what branch origin is currently on (if any; see below). To change it to another branch, you have to use git symbolic-ref HEAD refs/heads/<another_branch>.

  2. In some unusual scenarios, including when the default branch is renamed, a bare repo has no current, "checked out," default branch. In such a case, git branch | grep '^*' run from the bare repo directory will print nothing (the default branch has a * to the left of the default-branch name), and you can run the above git symbolic-ref ... command to select a default branch. (Also: you can run git branch <new_branch> to create a new one, if needed, but a default/current branch has to first be selected.)

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).

1
  • 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, 2014 at 18:10
16

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.

2
  • 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, 2014 at 20:51
  • 2
    +1. This was the only way I could delete a bad first commit on remotes/origin/master.
    – ctn
    May 26, 2015 at 16:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .