Could not find ref 'refs/heads/master' in refs/heads, refs/remotes/upstream or refs/remotes/origin


I’m getting the warning below when running SonarQube from within a Docker-container using Azure DevOps.

Could not find ref ‘refs/heads/master’ in refs/heads, refs/remotes/upstream or refs/remotes/origin
You may see unexpected issues and changes. Please make sure to fetch this ref before pull request analysis.

When building the Docker container I pass the arguments at build time

docker build \
  --build-arg sq_pr_branch=/d:sonar.pullrequest.branch=refs/heads/<branch> \
  --build-arg sq_pr_key=/d:sonar.pullrequest.key=<key> \
  --build-arg sq_pr_base=/d:sonar.pullrequest.base=refs/heads/master \
  -f test/Test.Dockerfile -t <container> .

We’re running SonarQube Developer Edition Version 8.6 (build 39681)


1 Like

The SonarQube Scanner uses git to detect what code was changed in the pull request. For that, it needs local access to the target of the pull request, which is master in your case.
Make sure that master is fetched before running the scanner.

What to do if the repository doesn’t contain the master branch, only main?

If you’re analyzing a pull request targeting main, main needs to be fetched and present in the local repository.


I am using SonarQube SonarQube v7.9.1 (Bulid 27448) Enterprise edition and Sonar Scanner v3.0.3.778.

My Main branch is configured to be master. In Team City, I clone the repo and only one branch, namely “integration”, exists in this local repo. No other branches are cloned. When performing a scan of C++ code, I use the option“integration” (i.e. I specify the same name as the branch I have checked out.)

As I understand it, because branch “integration” is not found in the regex, Sonar refers to my branch “integration” as a short-lived branch (SLB).

My questions are:

Q1. Are short-lived branches (i.e. “integration” in my case) analysed with respect to the Main branch (i.e. master)? That is, does Sonar analyse the delta between master and integration only? (i.e. it looks only at files changed since “integration” was last branched off of “master”)?

Q2. Does Sonar scanner need the “master” branch to be in the local repo clone too? i.e. do I need to do: “git fetch origin master:master” so that the scanner can access the branch “master” to determine the delta between the current checked out branch (“integration”) and the" master" branch?

If so, please would you point me to the Sonar documentation that explains all this so that I can understand it more fully?


Hi Will,

The answer is yes for both questions.

The documentation about branches for that version is here: Overview | SonarQube Docs

The concept of long lived branches and short lived branches no longer exists in more recent versions of SonarQube.