diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b8bf29826722aa1c6b650f30d7ab55af06940b29..80213f394f7ff120b9f7c4aea4bab729c3fa9e2f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,12 +6,13 @@ variables:
 
 before_script:
 - echo "Running make concurrently with $(nproc) cores, where possibly"
+# make sure we can update submodules and apply the patches
+- git submodule foreach --recursive git reset --hard HEAD
+- git submodule foreach --recursive git clean -fdx
 # work around https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/2148
 - git submodule sync --recursive
 - git submodule update --init --recursive
 # end workaround
-# make sure we can apply the patches
-- git submodule foreach --recursive git reset --hard HEAD
 - patches/apply_patches.sh
 # detect number of processors, but make sure never to run with -j"", as the
 # build host would likely run out of memory