Have you tried checking repository ownership and permissions and reviewing the safe.directory configuration in the runner environment. Also try avoiding using debug mode for regular use.
Search for workflows of open-source projects (e.g. on GitHub) and you will find many examples
However, lets be constructive and focus on the actual problem…
I digged deeper and now the problem totally makes sense. Before I was wondering why GitLab CI can checkout the code with git and then later in the build working on that cloned repo it does not have git. But the thing is that you are using image tag to define a container where the build job is running on. GitLab CI just mounts the cloned repo into the container so it is available but with your container you are in charge of installing git.