Git

How to Change Default Branch in GitLab

Like local machines, remote servers such as GitLab also have branches for storing the source code files. On GitLab, when users make a new project, it also makes a default branch inside the remote repository. The default branch cannot be removed once created. However, it can be changed.

In this guide, we will discuss how to change GitLab’s default branch.

How to Change the Default Branch in GitLab?

To modify the default branch in GitLab, try out the below-provided steps:

  • Open your preferred browser and move to the GitLab account.
  • Access the “Settings” and choose the “Repository” option.
  • Scroll to the “Branch defaults” and expand it.
  • Click on the desired branch name to which you are required to make it the default branch.

Step 1: Access GitLab Repository

First of all, access the GitLab account, click on the desired repository, and move to it:

Step 2: Access Repository Settings

Then, hit the “Settings” option from the left menu and access it:

Step 3: Choose the “Repository” Option

Next, choose the “Repository” option from the expanded “Settings” category:

Step 4: Locate the Default Branch

To change the default branch from the GitLab, locate the “Branch defaults” and click on the “Expand” button to view the details:

Step 5: Change the Default Branch

After that, hit the below-highlighted branch field. According to the expanded branch list, currently “main” is the default branch:

Now, hit on the desired branch name to which you want to make a default. Here, we have selected the “master” as a default branch name:

Step 6: Save Changes

Save all changes by pressing the “Save Changes” button:

That’s all! We have provided the instructions for changing the default branch in GitLab.

Conclusion

To change the default branch in GitLab, first, open your desired browser and redirect to the GitLab account. Then, access the settings and choose the “Repository” option. Next, locate the “Branch defaults” and expand its detail. After that, select the branch name to which you want to make the default branch and save the changes. This guide illustrated the way for changing GitLab’s default branch.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.