6

I have tried the following command and it fails.

git push origin :next
remote: error: denying ref deletion for refs/heads/next
To blah.git
 ! [remote rejected] next (deletion prohibited)
error: failed to push some refs to 'blah.git

I am using gitolite and cannot find any of this error message in the hooks. How can I disable this so that I can delete or rename this remote branch? When I run git branch -r -d origin/next, it appears to go away, but the next git pull brings it right back.

rtn
  • 127,556
  • 20
  • 111
  • 121
user561638
  • 1,299
  • 3
  • 15
  • 26
  • The "denying ref deletion" portion of the message comes from Git itself. See: builtin/receive-pack.c line 369: rp_error("denying ref deletion for %s", name); – Matthew McCullough Apr 20 '11 at 23:11
  • 1
    "git branch -r -d origin/next" only deletes the local-disk 'cache' copy of a remote tracked branch. Only "push" issues commands over the wire in this scenario. Thus, pull will recreate it (the cache). You are effectively asking it to do so. A remote deletion only occurs via "git push REMOTENAME :branchname" or "git push --delete REMOTENAME branchname" – Matthew McCullough Apr 20 '11 at 23:18
  • 1
    Thanks Matthew, so how do I remove my remote branch? – user561638 Apr 20 '11 at 23:56

2 Answers2

5

Make sure in your gitolite config, you have the rewind flag on so instead of RW use RW+. That will allow you to delete branches and commits.

git push -f origin :next

Mohamed Mansour
  • 39,445
  • 10
  • 116
  • 90
5

This looks like the error you get when you try to push to a repo that has denyDeletes = true. It's intended to prohibit you from rewriting history in the remote (it is usually accompanied by denyNonFastForwards = true). That being the case, you can only delete the branch by deleting it on the remote; --force won't work.

ebneter
  • 20,795
  • 9
  • 30
  • 30
  • So I am the admin. How do I turn these off? – user561638 Apr 20 '11 at 14:42
  • nevermind. I found the gitconfig line to use and I set it to false, and I still get the same error when I try to remove the remote branch. – user561638 Apr 20 '11 at 14:45
  • 2
    You set it on the remote, correct? If that still doesn't work, there is always the brute force method: Go to the remote and do `git branch -D next`. – ebneter Apr 20 '11 at 19:48
  • 2
    Even with gitolite, a bare repository is still a repository. It responds to the git branch commands (e.g. ssh into the box and cd to the repo's folder). A "git branch -D branchname" should do it. The capital D means force the deletion. – Matthew McCullough Apr 21 '11 at 00:00
  • This worked and it also helped me to understand that I should execute git gc in the bare repo. so cool! – user561638 Apr 21 '11 at 21:05
  • git branch -D next didn't worked for me :( @user561638 can you please describe how did you resolve it ? – Aguid Jun 02 '21 at 14:37