First analysis of branch does not show correct issues of new code

Must-share information (formatted with Markdown):

  • which versions are you using: Sonarqube on premise Version 9.9.2 (build 77730)
  • how is SonarQube deployed: Docker Image


I have encountered an issue with Sonar, specifically related to the identification of code smells in new code changes. It appears that newcode smells are being reported in the “overall code” category, while they are not shown in the section newly added code.


In a recent branch, the only code change made was on line 85 of the file (shown below):

Problem Details

The problem is that code smells introduced in this branch’s new code are not being categorized as such. Instead, they are being only shown as the “overall code,” which could lead to misunderstandings and difficulties in identifying and addressing these issues.

The problematic branch was pushed directly with the changes to the VCS. Starting from the second build of the branch, all is fine.

We have defined new code as new code relative to the main branch.

Expected Behavior

I expect the code analysis tool to correctly recognize code smells introduced in new code changes within a branch and categorize them as “new code”.

Steps Taken

I have reviewed the code changes made in this branch and confirmed that the only modification was on line 85. I expected the code smell to be associated with this new code change.


Your screenshots are strangely narrow. Nonetheless, I can see that the issue is dated “6 days ago”.

What I can’t tell is what your new code period is. Would you mind providing that? And also the analysis log of scan that raised the issue, if you still have it?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.


Hi Ann,

thanks for your reply!

Our new code period is ‘Reference Branch’, so that we just take our main branch as reference branch.

The analysis in question was performed on a branch different from ‘main’.

Find attached the log of the run. Where needed, sensitive information was replaced by ‘[…]’.
sonar_log.txt (11.1 KB)


Thanks for the log. This is about the SCM data available to analysis:

WARN: Could not find ref 'main' in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin

Make sure the main branch is fetched before running analysis.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.