20.1.2021

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.

Screen_Shot_2021-01-17_at_19.23.07

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.

Screen_Shot_2021-01-17_at_19.33.43

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)!

Proposal

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.

Jan

Softwareentwickler

Zur Übersicht

Standort Hannover

newcubator GmbH
Bödekerstraße 22
30161 Hannover

Standort Dortmund

newcubator GmbH
Westenhellweg 85-89
44137 Dortmund