Sonar: Could not find a default branch to fall back on error

Using Gitlab CI/CD, I recently set up a SonarQube analysis for my project. The following error occurred:

Could not find a default branch to fall back on, and none was specified.

The error message was somewhat misleading is my case. My mistake was a misconfiguration of the sonar.projectKey and sonar.projectName properties, which I had set to a different value than previously configured on Sonar Cloud.

GitLab CI, Semantic Release, Environment Branches and Continuous DeploymentJS/TS tooling overview