diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 9f06b16fae391f1285911c641a7ba55c50a41ad3..54eabffd555080011a9235cfc5e886baf81fba20 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -129,7 +129,7 @@ include:
   before_script:
     - set -euo pipefail
     - module purge
-    - module load gcc/11.2.0-gcc-11.2.0
+    - module load git gcc/11.2.0-gcc-11.2.0
     - |
       # Install libcheck
       if test ! -d "${LIBCHECK_ROOT}"; then
@@ -165,6 +165,24 @@ include:
         exit 1
       }
       rm -rf "${BUILD_LOG}" "${compiler_warnings}"
+    - |
+      # Check if there are untracked files
+      untracked_files=$( \
+        git -C "${CI_PROJECT_DIR}" \
+        -c core.excludesfile= \
+        ls-files --others \
+        --exclude-standard \
+        --exclude="${LIBCHECK_ROOT#"${CI_PROJECT_DIR}"}" \
+        --exclude="${INSTALL_PREFIX#"${CI_PROJECT_DIR}"}" \
+      )
+      test -z "${untracked_files}" || {
+        printf "${RED}The job produced unexpected files:\n${untracked_files}\n\
+      If the files above are CI-specific, please, update the \
+      '${CI_CONFIG_PATH}' file either to remove the files before running this \
+      check or to exclude them from the check. Otherwise, update the \
+      '.gitignore' file.\n${DEFAULT}"
+        exit 1
+      }
   rules:
     - if: $CI_PIPELINE_SOURCE == "web"
       when: manual