Inject CI job token as an insteadOf rule in.git/config for repositories on the current-instance

Description

Cloning private repositories from the current instance requires credentials. This is especially common for Go projects spread across multiple repositories.

In many cases, the CI/CD job token grants this access, and users can add a simple step to their build:

git config --global url."${CI_SERVER_PROTOCOL}://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}".insteadOf "${CI_SERVER_URL}"

Notice that this is completely generic. Wouldn't it be nice if this was the default?

Proposal

When initializing the repository for the current project, inject an insteadOf rule like the above into .git/config.

Links to related issues and merge requests / references