diff --git a/scripts/cmake/PreFind.cmake b/scripts/cmake/PreFind.cmake
index e0b08c78904ca5c8f4fc9ec97d9139d43abb3a34..58aa681e37f81aa347802835eae9a7c4cb718807 100644
--- a/scripts/cmake/PreFind.cmake
+++ b/scripts/cmake/PreFind.cmake
@@ -1,22 +1,24 @@
 find_package(Git REQUIRED)
 
-execute_process(COMMAND ${GIT_EXECUTABLE} status
-    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
-    RESULT_VARIABLE IS_GIT_REPO
-    OUTPUT_QUIET)
-if(IS_GIT_REPO GREATER 0)
-    set(IS_GIT_REPO FALSE CACHE INTERNAL "")
-    if(DEFINED OGS_VERSION)
-        message(WARNING "Using user-provided OGS_VERSION: ${OGS_VERSION}!")
-        message(WARNING "Submodule setup is skipped!")
+if(NOT IS_GIT_REPO)
+    execute_process(COMMAND ${GIT_EXECUTABLE} status
+        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+        RESULT_VARIABLE IS_GIT_REPO
+        OUTPUT_QUIET)
+    if(IS_GIT_REPO GREATER 0)
+        set(IS_GIT_REPO FALSE CACHE INTERNAL "")
+        if(DEFINED OGS_VERSION)
+            message(WARNING "Using user-provided OGS_VERSION: ${OGS_VERSION}!")
+            message(WARNING "Submodule setup is skipped!")
+        else()
+            message(FATAL_ERROR "No git repository found at ${PROJECT_SOURCE_DIR}! "
+                "Please use git to obtain the source code! See "
+                "https://www.opengeosys.org/docs/devguide/getting-started/get-the-source-code/"
+                " OR manually set the OGS_VERSION variable.")
+        endif()
     else()
-        message(FATAL_ERROR "No git repository found at ${PROJECT_SOURCE_DIR}! "
-            "Please use git to obtain the source code! See "
-            "https://www.opengeosys.org/docs/devguide/getting-started/get-the-source-code/"
-            " OR manually set the OGS_VERSION variable.")
+        set(IS_GIT_REPO TRUE CACHE INTERNAL "")
     endif()
-else()
-set(IS_GIT_REPO TRUE CACHE INTERNAL "")
 endif()
 
 if(OGS_USE_PYTHON)