0

I have a bare git repo on a server with the default branch called master. I want to change the name to main.

When I search for instructions I am always told to change the default branch on GitHub to the new main branch before deleting the master branch. But my repo is not on GitHub.
When I try to delete the master I get this error message:

$ git push origin --delete master
remote: error: By default, deleting the current branch is denied, because the next
remote: error: 'git clone' won't result in any file checked out, causing confusion.
remote: error: 
remote: error: You can set 'receive.denyDeleteCurrent' configuration variable to
remote: error: 'warn' or 'ignore' in the remote repository to allow deleting the
remote: error: current branch, with or without a warning message.
remote: error: 
remote: error: To squelch this message, you can set it to 'refuse'.
remote: error: refusing to delete the current branch: refs/heads/master
To server:projects/repo.git
 ! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to 'server:projects/repo.git'

What I did so far:

$ git branch -m master main
$ git push -u origin main

How can I delete the master branch and set the main branch as new default so that future git clone won't result in an empty directory checked out?

fredrik
  • 6,483
  • 3
  • 35
  • 45
  • You need to dell your server which branch to consider to be the main branch. How this is done depends on which server software you are using. – fredrik Sep 17 '20 at 11:10
  • 1
    Create the main branch, check it out and delete the master branch. – dan1st Sep 17 '20 at 11:54

1 Answers1

6

I found the solution which worked for me here:
Git: Correct way to change Active Branch in a bare repository?

As I have access to my bare repo on the server I did:

[server:~/projects/repo.git]$ git symbolic-ref HEAD refs/heads/main

Then on my local copy I could git push origin --delete master without error.

A new git clone of this repo checked out all files and the main branch as default.