How to change the main branch in BitBucket?
Asked Answered
R

4

50

I have a repo on bitbucket with two branches. First branch is master with a fake content, then I have another one called trunk with the correct content.

I would like to change the main branch to trunk (actually is master). I found that in the repo adminsitration are on bitbucket web I could change this but I couldn't.

Finally I would like to understand if is possible to do this through terminal from my local repo.

Maybe an easy thing is to delete contents from master and merge trunk into master and the delete trunk but I neither know how to do this.

Racehorse answered 31/5, 2016 at 15:59 Comment(0)
C
84
  1. Repositories.
  2. Click on a repository.
  3. Repository settings.
  4. Advanced
  5. Main branch.
  6. Change it from master to main or something else.
  7. Save changes.

Back in the day

  1. Repositories

enter image description here

  1. Select repository
  2. Settings

enter image description here

  1. Main branch: master

enter image description here

  1. Save repository details

enter image description here

Curative answered 8/2, 2017 at 14:25 Comment(0)
R
11

Relevant for folks who are looking at this question in 2022

The menu options have changed a bit. The following steps can help you achieve the same.

  1. Go to your repository.
  2. Click on repository settings on the left-hand side menu bar.
  3. Click on repository details ( if not already selected ).
  4. You should be able to see a dropdown with advanced written on it ( refer to image ).
  5. In that drop-down menu, you should be able to find the main branch settings.

I hope it helps :)

enter image description here

Rammish answered 16/8, 2022 at 7:50 Comment(2)
Currently your solution does not work. Save is deactivated.Bernhard
Thank you! The word "ADVANCED" does not look like a link, or a button, or an accordion - you wouldn't know you could click on it unless you read this answer.Aalii
A
1

With two branches named trunk and master, change master to the HEAD of the repository and delete trunk:

git symbolic-ref HEAD refs/heads/master
git branch -d trunk

From:

https://answers.atlassian.com/questions/280944/how-to-change-main-branch-in-bitbucket

Aftershock answered 31/5, 2016 at 16:4 Comment(3)
This git symbolic-ref command what does? These operations are on local repo or on remote repo?Racehorse
Is solution working for new branch to be set up as default branch? I need to set new default branch other than master, I need to each time do the same thing as first aswer, need to write and automation script which do the same for 4 repositories.Superdreadnought
It is also possible to make this change directly in the HEAD file on the file server. (i'm using Bonobo git server)Bodoni
E
0

You can merge the trunk into master (you may have to force it) and then delete the trunk

git checkout master
git merge trunk
Employment answered 31/5, 2016 at 16:49 Comment(1)
Please don't use GitHub-flavoured Markdown on Stack Overflow. For code blocks, use a 4-space indent.Transcendental

© 2022 - 2024 — McMap. All rights reserved.