I'm trying to remove a remote branch with git:

rpinson@rpinson:~/dev/charismanie$ git remote show origin 
* remote origin
  Fetch URL: git@github.com:raphink/Charismanie.git
  Push  URL: git@github.com:raphink/Charismanie.git
  HEAD branch: xetex
  Remote branches:
    master tracked
    xetex  tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)
rpinson@rpinson:~/dev/charismanie$ git push origin :xetex
remote: error: refusing to delete the current branch: refs/heads/xetex
To git@github.com:raphink/Charismanie.git
 ! [remote rejected] xetex (deletion of the current branch prohibited)
error: failed to push some refs to 'git@github.com:raphink/Charismanie.git'

Is there a way I can remove this branch from the list of "Remote branches" so I can remove it?


The branch was set as default on github, preventing it from being deleted.

On github, I went to "Administration" in the project, reset the default branch to "master" and I was able to remove the xetex branch.

  • 1
    Awesome! was looking how to do that on GitHub for 20 minutes before I searched here.
    – rlemon
    Jan 20 '12 at 20:55
  • 1
    This also happens with BitBucket, and is fixed in a similar fashion.
    – John B
    Mar 8 '13 at 14:35
  • Is there no pure git way of doing it? Feb 1 '14 at 21:19
  • github default branch is not a git feature, so no.
    – raphink
    Feb 2 '14 at 20:55
  • I also encounter with this problem. I think it's better to have some tips showing that it's default?? I am stuck with it all day....
    – WesternGun
    Aug 31 '16 at 11:16

For what it's worth in BitBucket:

  • click on Settings in the left menu
  • under 'Repository Details' find 'Main Branch' drop down menu
  • select a different branch from the one you want to delete

There's also an option to prevent branch deletion under the 'Branch management' section, but you have to actively set that yourself first.

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.