I had this issue as well. Thought I would reply here with my solution in case it helps anyone. What happens was that in the CI server machine in the git repo there was an old local branch of the same name as the branch provided to the sonar-scanner -Dsonar.pullrequest.base parameter. In my case it was a branch called “develop”. So even though at the time of the build the local “develop” was not checked out, per the comment above sonar-scanner gives priority first to checking refs/heads/develop to figure out the commit ID to use as the base reference. Once I deleted that local branch the scanner went back to using refs/remotes/origin/develop to get the commit id of “develop” and all was good.