Change main branch in Sonarqube without deleting branch
Asked Answered
E

2

18

I am trying to change my main branch in Sonarqube from master to mainline as I have been doing my analysis on mainline for the past few months.

This post below in the Sonar community says that I have to delete the mainline branch then rename the master branch. The problem with this approach is that I would lose all of my history which I do not want to do. https://community.sonarsource.com/t/how-to-change-the-main-branch-in-sonarqube/13669/37

Is there anyway to change the main brach to another branch without losing all of our scan history?

Using: Developer Edition - Version 9.2.1

Picture of Branches

Elmaelmajian answered 6/4, 2022 at 16:18 Comment(4)
Have you tried the steps mentioned here community.sonarsource.com/t/…Galatea
Yes, I linked that thread in the question. It requires you to delete your old branch which I don't want to do because I want to keep the historyElmaelmajian
Update: this feature under development as of April 2023 & is expected in 10.X. There is a tile for setting a new main branch on the roadmap sonarsource.com/products/sonarqube/roadmap. This comment has additional details: community.sonarsource.com/t/…Smallminded
Released now in 10.2Perihelion
L
4

Found this on the sonar source community. Seems like this was missing feature and being released on 10.2

enter image description here

Leeward answered 15/9, 2023 at 11:24 Comment(1)
V
1

You need to be an administrator of the project.

  1. Navigate to the right side of the panel, open the Project Settings combo box and select "Branches & Pull Requests":

    enter image description here

  2. You will see the branch list. Under "Actions", expand the cogwheel icon and click to "Rename branch" so feel free to rename the default master to for example develop or mainline in your case.

    enter image description here

    Beware. If develop already exists in the list of branches, you have to first delete develop and then rename master to develop, otherwise it is not possible to change the main branch. In such a case, you need to run the build again, i.e. publish a new analysis to Sonar.

Once this is done, Sonar will display the develop branch as a default one.

Visby answered 24/10, 2023 at 13:27 Comment(2)
I think this fails to satisfy this part of OP question: without losing all of our scan history.Bahia
The OP can create a new branch (archive) and do the renaming: mainline -> archive and master -> mainline. I'd tested it first on different branches, though.Visby

© 2022 - 2024 — McMap. All rights reserved.