How to delete the master branch
If you want to remove the default branch named master from your git repository this is how it works:
On your local machine
- after initializing your project create a new branch based on master and push it to origin
git branch -m master main
git push —-set-upstream origin main
- delete your local master branch
git branch -D master
On gitlab
You have to be the owner of the repository in order to change these settings.
gitlab has set that the master branch as default and protected, which means you can not just remove it from your local machine. You first need to remove the protection and set main as your new default.
So in order to be able to remove the master, we have to first remove the default and the protected flag. You can do this as a project maintainer in Settings / Repository
Choose your new main branch as default branch in the dropdown. And then move over to Protected Branches
Choose main branch as protected and set rules for allowance of merging, pushing and owner approval and save your changes. Press the Unprotect Button for master.
Now you are able to delete the master branch.
On github
You have to be owner of the repository in order to change these settings.
Depending on your repositories settings the master branch can be protected, but is always set to default. First we have to choose the main branch as our new default branch.
On the branches overview master is marked as default. Click on the Change default branch Button.
On the dropdown, choose main instead of master and click update. On the Branch protection rules for master click edit.
Change the branch name pattern to main and save changes. Back on the Branch Overview, delete master.
Thank you for deleting master.