Description:
We’ve noticed that when creating SonarQube projects via the REST API (/api/projects/create), the global default main branch setting (sonar.projectCreation.mainBranchName) is not applied.
Currently:
UI-created projects: Respect this setting.
API-created projects: Ignore this setting, defaulting to master.
DevOps platform imports: Also ignore this setting.
Impact:
This behavior causes inconsistency between UI-created and API-created projects. In environments where projects are provisioned automatically via CI/CD pipelines, the main branch defaults to master regardless of organizational conventions (e.g., main), and there is no API mechanism to override it.
This has several implications:
Teams must manually run a first analysis on the intended main branch to correct it.
“If you add your project manually, your main branch defaults to the name master.”
Observed behavior: Projects created via /api/projects/createignoresonar.projectCreation.mainBranchName and default to master.
Requested Enhancement / Question:
Can the API provide an option to specify the main branch at project creation?
Alternatively, can the global default sonar.projectCreation.mainBranchName be applied to API-created projects, just like UI-created projects?
Environment / Version:
SonarQube Server Version: Developer Edition v2025.5
API: /api/projects/create
Additional Notes:
This limitation currently requires extra manual steps or first-analysis workarounds to ensure consistent main branch naming across automated projects.
That said, this still requires an extra step in automated provisioning pipelines. Ideally, the global sonar.projectCreation.mainBranchName setting would also apply to API-created projects, or the /api/projects/create endpoint would allow explicitly specifying the main branch.
Thank you for the detailed report, the context is very helpful.
Immediate workaround: The /api/projects/create endpoint supports an explicit mainBranch parameter since v9.8, so you can include it directly in your API call without needing the extra rename step:
Regarding the global setting behavior: From what I can tell, the server-side code for /api/projects/create does fall back to the sonar.projectCreation.mainBranchName global setting when the mainBranch parameter is not provided. This is the same code path used when creating projects via the UI, the difference is that the UI reads the setting and sends it explicitly in the request, whereas the API relies on the server-side fallback.
To help us investigate why you’re seeing master instead of main, could you run the following API call and share the output?
I wasn’t aware that mainBranch could be passed directly as a parameter to /api/projects/create, but including it in the request resolves the issue on our side. That’s definitely a cleaner approach than the rename step — thanks for pointing that out.
Regarding the second API call, here is the response we get: