Setting main branch in SonarCloud

As far as i can see, setting the main branch still isn’t possible without “hacky workarounds”

See 27669 and 1167.

I have found the rename API endpoint but it doesn’t work without issues (If the branch i want to have as main branch already exists, I get an error).

Also, I seem to remember that SonarCloud was supposed to take over the main branch defined in BitBucket (I can’t currently find the source for this though).

Are there any plans for this behavior to change in the near future?

Hey there.

When provisioning the project in the SonarCloud UI, the main branch should automatically get the right name.

If the default branch on Bitbucket is updated, that won’t translate to a change on the SonarCloud side.

What case are you running into? The default branch when the SonarCloud project is provisioned, or changing it after the fact?

I currently manage 50+ projects that are read from Bitbucket with a provisioning script and then created/updated in various CI/CD tools (SonarCloud included).

The main-branches in BitBucket are partly changed and have to be updated accordingly in SonarCloud. Therefore, it is mainly about this use case and not about the initial provisioning.

Hey there.

I can confirm that in this case, the main branch won’t be set correctly by default (coming back to the conversation here, it’s because the project isn’t bound).

And, even when a project is bound, should the default branch change… you’re stuck in this situation as well.

So for now, you have to either rename the main branch (and lose history / have a history that actually represents two branches).

I’ll move this to Suggest New Features so that it can get attention from the right folks, and maybe get some votes.