291

I accidentally pushed my local master to a branch called origin on gitlab and now it is the default. Is there a way to rename this branch or set a new master branch to master?

1

14 Answers 14

209

Updated:

Prerequisites:

  • You have the Owner or Maintainer role in the project.

To update the default branch for an individual project:

  1. On the left sidebar, select Search or go to find your project.
  2. Select Settings > Repository.
  3. Expand Branch defaults. For Default branch, select a new default branch.
  4. Optional. Select the Auto-close referenced issues on default branch checkbox to close issues when a merge request uses a closing pattern.
  5. Select Save changes.

enter image description here

To change a default branch name for an instance or group:

  1. On the left sidebar, at the bottom, select Admin Area.
  2. Select Settings > Repository.
  3. Expand Default branch.
  4. For Initial default branch name, select a new default branch.
  5. Select Save changes.

change group

7
  • 14
    They keep moving it so I have to keep changing my correct answer. All other high voted answers were correct at the time they were posted.
    – Jeff
    Commented Sep 6, 2019 at 18:19
  • 2
    This applies as of February 2021. Until the next change...
    – leanne
    Commented Feb 27, 2021 at 18:22
  • 1
    Hello from 14.0! Although they changed it, so it uses sentence case, the option is still on the same spot.
    – Hans5958
    Commented Jun 25, 2021 at 5:03
  • All the branches appear in the dropdown... except the one I want. Figures. Commented Jul 13, 2021 at 22:16
  • is it possible to setting this on empty project? because I got default branch cannot be chosen for an empty project. and gitlab stopping me from pushing my glorious pure innocence master branch damn, its just a repository.
    – buncis
    Commented May 15 at 12:55
126

To change default branch in GitLab:
1. Settings > General > General project settings > Expand
2. Default Branch > Change your project default branch
3. Save changes

enter image description here

125

In 8.0+ it looks like this was moved into the project. If you open your project and go to the gear icon on the right, then "Edit Project" you can set the default branch for the project.

2
  • 1
    Dear reader, look at other answers for references to newer version of gitlab
    – human
    Commented Jun 8, 2019 at 1:54
  • thanks @bigdatamann I've updated the correct answer to the most updated current version
    – Jeff
    Commented Aug 14, 2019 at 16:33
61

For gitlab v10+ (as of Sept 2018), this has moved to settings-> repository -> default branch

enter image description here

As stated by @Luke this is still valid as on 4/1/2021

4
  • 3
    As of March 2019, this is still the correct answer!
    – Alex
    Commented Mar 14, 2019 at 11:19
  • Also not "Settings", "Expand one of the many options in the main content area", but "Settings", "Repository" (in the sidebar). AKA gitlab.com/you/your-repository/settings/repository
    – joeforker
    Commented Jun 7, 2019 at 12:49
  • 3
    This is still correct as of Jan 4th, 2021. (GitLab Enterprise Edition 13.8.0)
    – Luke
    Commented Jan 4, 2021 at 22:15
  • A default branch cannot be chosen for an empty project.
    – buncis
    Commented May 15 at 12:42
58

To change the default branch in Gitlab 7.7.2:

  • Click Settings in the left-hand bar
  • Change the Default Branch to the desired branch
  • Click Save Changes.
3
  • 6
    Why is this obvious option so hard for me to find too?
    – istrasci
    Commented Aug 13, 2015 at 18:33
  • GitLab Community Edition 8.8.5 does not have "Settings" in the left-hand bar.
    – Phrogz
    Commented Jul 14, 2016 at 20:40
  • 2
    They changed the UI so I've changed the correct answer to @Mason
    – Jeff
    Commented Jul 29, 2016 at 16:43
21

In Gitlab version v11.4.4-ee, you can:

  1. Setting
  2. Repository
  3. Default Branch

enter image description here

1
  • A default branch cannot be chosen for an empty project.
    – buncis
    Commented May 15 at 12:42
17
  1. Settings
  2. General
  3. General Project Settings

Setting the default branch

0
13

In the latest GitLab Community Edition version 9.2.2.:

  1. You have to click on 'Settings' tab located at right most on tabs panel after opening the project.
  2. Under 'Settings' you will get section 'Default Branch' dropdown which will give you all branches for the repository. Select the desired branch.
  3. Scroll down to hit green colored 'Save changes' button located just after 'Project Avatar'.

Please refer image below:

enter image description here

8

See also GitLab 13.6 (November 2020)

Customize the initial branch name for new projects within a group

When creating a new Git repository, the first branch created is named master by default.

In coordination with the Git project, broader community, and other Git vendors, GitLab has been listening to the development community’s feedback on determining a more descriptive and inclusive name for the default branch, and is now offering users options to change the name of the default branch name for their repositories.

Previously, we shipped the ability to customize the initial branch name at the instance-level and as part of 13.6, GitLab now allows group administrators to configure the default branch name for new repositories created through the GitLab interface.

See Documentation and Issue.

https://gitlab.com/gitlab-org/gitlab/uploads/2959ef65431bf4ffac659992360d6d8d/image.png


GitLab 13.9 (Feb 2021) details:

Git default branch name change

Every Git repository has an initial branch. It’s the first branch to be created automatically when you create a new repository.
By default, this initial branch is named master.

Git version 2.31.0 (scheduled for release March 15, 2021) will change the default branch name in Git from master to main.

In coordination with the Git project and the broader community, GitLab will be changing the default branch name for new projects on both our SaaS (GitLab.com) and self-managed offerings starting with GitLab 14.0.
This will not affect existing projects.

For more information, see the related epic and the Git mailing list discussion.

Deprecation date: Apr 22, 2021


As promise, with GitLab 13.11 (Apr. 2021):

Git default branch name change

Every Git repository has an initial branch.
It’s the first branch to be created automatically when you create a new repository.

By default, this initial branch is named master.
Future Git versions will change the default branch name in Git from master to main.

In coordination with the Git project and the broader community, GitLab will be changing the default branch name for new projects on both our SaaS (GitLab.com) and self-managed offerings starting with GitLab 14.0.
This will not affect existing projects.

GitLab has already introduced changes that allow users to change the default branch name both at the instance-level (for self-managed users) and at the group-level (for both SaaS and self-managed users).
We encourage users to make use of these features to set default branch names on new projects.

For more information, see the related epic and related blog post.

2
  • This was helpful, as was the screenshot at stackoverflow.com/a/57492760/470749
    – Ryan
    Commented Nov 30, 2020 at 15:35
  • 1
    @Ryan Thank you. I forgot the screenshot indeed. I have edited the answer.
    – VonC
    Commented Nov 30, 2020 at 15:38
3

Settings > Repository > Default Branch

enter image description here

0
2

December, 2022

settings >> repository >> Branch defaults :: expand and set your desire branch.

1

First I needed to remote into my server with ssh. If someone has a non ssh way of doing this please post.

I found my bare repositories at

cd /var/opt/gitlab/git-data/repositories/group-name/project-name.git

used

git branch 

to see the wrong active branch

git symbolic-ref HEAD refs/heads/master

to change the master to to be the branch called master then use the web interface and "git branch" to confirm.

1

In Gitlab CE 9.0, You can change the default branch from the Settings Tab in a repository's header.

1

For GitLab 11.5.0-ee, go to https://gitlab.com/<username>/<project name>/settings/repository.

You should see:

Default Branch

Select the branch you want to set as the default for this project. All merge requests and commits will automatically be made against this branch unless you specify a different one.

Click Expand, select a branch, and click Save Changes.

Not the answer you're looking for? Browse other questions tagged or ask your own question.