diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 473ff47398902a4486178c5c347ce49d2628ffb4..e8982562f2b144fed3f43a3ed490b1091e99bc07 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -69,6 +69,8 @@ stages:
     BB_ENV_PASSTHROUGH_ADDITIONS: DISTRO MACHINE
     SOURCE_MIRROR_URL_CH: http://114.116.235.68/source-mirror
   before_script:
+    # Tell git this repository is safe even if cloned with a different uid
+    - git config --global --add safe.directory $CI_PROJECT_DIR
     # The repo tool seems to insist on having a branch checked out or
     # something like that... Without this we get errors like
     #     fatal: couldn't find remote ref refs/heads/master