Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I remove a remote branch when I get an error?

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.

like image 830
user561638 Avatar asked Apr 19 '11 22:04

user561638


People also ask

How do I force delete a remote branch?

Deleting remote branches To delete a remote branch, you can't use the git branch command. Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .

Can I delete a remote branch?

Instead of using the git branch command that you use for local branches, you can delete a remote branche with the git push command. Then you specify the name of the remote, which in most cases is origin . -d is the flag for deleting, an alias for --delete . remote_branch_name is the remote branch you want to delete.

How do I force delete a branch that has potentially unmerged changes?

Delete a branch The -f or --force flag in combination with -d (or --delete ), allows deleting the branch containing unmerged changes.

How do I remove a remote tracking branch?

You can use the prune subcommand of git-remote for cleaning obsolete remote-tracking branches. Alternatively, you can use the get-fetch command with the --prune option to remove any remote-tracking references that no longer exist on the remote. That's all about deleting remote-tracking branches in Git.


2 Answers

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

like image 121
Mohamed Mansour Avatar answered Sep 24 '22 17:09

Mohamed Mansour


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.

like image 25
ebneter Avatar answered Sep 25 '22 17:09

ebneter