13

In a git project I did some refactoring in a branch and now this branch should be a new project. I moved this project from github to bitbucket. Now I want to delete the old master and make the refactoring branch the new master.

I tried to delete the master:

$ git branch -D master
Deleted branch master (was a947288).
$ git push origin :master
remote: error: refusing to delete the current branch: refs/heads/master
 ! [remote rejected] master (deletion of the current branch prohibited)

In the bitbucket frontend I couldn't delete the master neither. So how could I achive that? Or do I have to create a new project and push the refactoring branch into its master?

s.meissner
  • 506
  • 2
  • 5
  • 17

2 Answers2

23

You have to change the main branch of bibucket before being able to delete it. As long as master is the main branch, bitbucket will prevent you to do so (which make sense).

In Bitbucket UI:

  • Select the repository
  • Select Administration
  • In Repository Details, set Main branch

Duplicates :

Community
  • 1
  • 1
Cyril Gandon
  • 16,830
  • 14
  • 78
  • 122
3

When you are pushing a deletion, you must first change the default branch (on GitHub) to your new branch.
That means you must have first push your new branch on GitHub in order to select it as default branch.

Then you can delete master on GitHub.

The same idea applies on BitBucket:

  1. Select the repository
  2. Select Administration
  3. In Repository Details, set Main branch
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250