Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting remote master branch, refused due to being the current branch

How do I delete a remote master branch from GitHub/Bitbucket?

I'm trying:

# git push bb --delete master remote: bb/acl: user is allowed. accepted payload.[K remote: error: refusing to delete the current branch: refs/heads/master[K To ssh://[email protected]/user/reponame.git  ! [remote rejected] master (deletion of the current branch prohibited) error: failed to push some refs to 'ssh://[email protected]/user/reponame.git'  

Also I tried

git push bb :master 

But all this does not work.

like image 776
Tomilov Anatoliy Avatar asked Dec 26 '12 12:12

Tomilov Anatoliy


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 .

Is it possible to delete master branch in git?

Can the master branch be deleted? The master branch is just a type of branch in the repository, which is also the default branch by default. But, as a rule in Git, default branches cannot be deleted. So, to delete the master branch first, the user has to change the default branch.

How do I force delete a branch in GitHub?

The command to delete a local git branch can take one of two forms: git branch –delete old-branch. git branch -d old-branch.


2 Answers

Note: for Bitbucket, you would change the default branch by accessing the settings of your repository, and changing the branch at the "Main branch" combo box.

Main branch on Bitbucket

Once the main branch is no longer master, then you can push and remove master.

MarsAndBack confirms in the comments this applies to GitHub as well.

like image 148
VonC Avatar answered Oct 26 '22 08:10

VonC


In the settings block on the options tap in the settings page (well, just click on the Settings tab on your GitHub repository page), you are able to change the default branch (you need to have the other default branch on GitHub as well).

Change default branch on GitHub

After you have done that, you are able to remove it:

$ git push bb :master 
like image 29
Wouter J Avatar answered Oct 26 '22 09:10

Wouter J