Reputation: 4830
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?
Upvotes: 299
Views: 260421
Reputation: 5058
Updated:
Prerequisites:
To update the default branch for an individual project:
Search or go
to find your project.Settings
> Repository
.Branch defaults
. For Default branch
, select a new default branch.Auto-close referenced issues on default branch
checkbox to close issues when a merge request uses a closing pattern.Save changes
.To change a default branch name for an instance or group:
Admin Area
.Settings
> Repository
.Default branch
.Initial default branch name
, select a new default branch.Save changes
.Upvotes: 218
Reputation: 21
December, 2022
settings >> repository >> Branch defaults :: expand and set your desire branch.
Upvotes: 2
Reputation: 211
In Gitlab version v11.4.4-ee, you can:
Upvotes: 21
Reputation: 1323953
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.
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 namedmaster
.Git version 2.31.0 (scheduled for release March 15, 2021) will change the default branch name in Git from
master
tomain
.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 frommaster
tomain
.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.
Upvotes: 8
Reputation: 2441
For gitlab v10+ (as of Sept 2018), this has moved to settings-> repository -> default branch
As stated by @Luke this is still valid as on 4/1/2021
Upvotes: 61
Reputation: 11
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.
Upvotes: 1
Reputation: 1463
To change default branch in GitLab:
1. Settings > General > General project settings > Expand
2. Default Branch > Change your project default branch
3. Save changes
Upvotes: 127
Reputation: 3664
In the latest GitLab Community Edition version 9.2.2.:
Please refer image below:
Upvotes: 13
Reputation: 842
In Gitlab CE 9.0, You can change the default branch from the Settings Tab in a repository's header.
Upvotes: 1
Reputation: 8846
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.
Upvotes: 125
Reputation: 9802
To change the default branch in Gitlab 7.7.2:
Upvotes: 58
Reputation: 4830
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.
Upvotes: 1