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?