diff --git a/templates/gitlab-ci-sonar.yml b/templates/gitlab-ci-sonar.yml
index 9426b28a61452d685512b82d5c514f2ebefff3b3..7b82087fe1d9fa3280fef53d925a4566255e09c4 100644
--- a/templates/gitlab-ci-sonar.yml
+++ b/templates/gitlab-ci-sonar.yml
@@ -292,6 +292,10 @@ sonar:
   services:
     - name: "$CI_REGISTRY/to-be-continuous/tools/tracking:master"
       command: ["--service", "sonar", "1.3.1" ]
+  variables:
+    # Tells git to fetch all the branches of the project, required by the analysis task
+    # see: https://docs.sonarqube.org/8.5/analysis/gitlab-cicd/#header-2
+    GIT_DEPTH: 0
   before_script:
     - *sonar-scripts
     - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"