Use main as the default branch

Follow-up for Git main replaces master #41 (closed)

Local default

Starting in Git 2.28, git init will instead look to the value of init.defaultBranch when creating the first branch in a new repository.

$ git config --global init.defaultBranch main

GitLab group wide default

GitLab now supports setting a default branch name for new repositories. Custom initial branch name

Rename existing projects

To change it, you can use the move command in git to copy the entire master branch (and it's history) to a new branch like so:

$ git branch -m master main

We can then push it to our remote repository with:

$ git push -u origin main

Now that the main branch exists on GitLab we can change the settings there as well. In the project go to Settings -> Repository -> Section: Default Branch and select main in the drop down.


Changing the default branch setting does not update the protected branches. For this scroll down to Section: Protected Branches. There we can now add our new main branch and remove the protection from master.


As a final step we can now go to Repository -> Branches and delete the old master branch and are done.

Unless we hardcoded a reference to the master branch in CI (only: master)!


The default branch of the newcubator/devsquad project is already renamed. Give it a try and if no one posts a reason why we shouldn't we will start renaming active newcubator projects after the next devsquad.

Wir freuen uns Sie kennen zu lernen

Hat Sie unser Angebot überzeugt? Dann freuen wir uns, Sie kennen zu lernen. Kontaktieren Sie uns gerne für ein unverbindliches Erstgespräch.

newcubator GmbH
Freie-Vogel-Straße 369
44269 Dortmund
+49 231/586 873 80
newcubator GmbH
Bödekerstraße 22
30161 Hannover
+49 511/957 313 00