Search code examples
urlsshgitlabclonegitolite

Gitlab clone URL without namespace?


While migrating from gitolite to gitlab we found that gitlab does not support cloning URLs of the form:

gitlab.example.com:<my-repository>.git

Instead it demands a namespace (group, username or subgroup), like this:

gitlab.example.com:<namespace>/<my-repository>.git

Unfortunately this would break multiple build scripts. Is it possible to do this another way?

I've already tried to create a group with a blank namespace but that's forbidden.

Our expected behavior was to clone without the namespace in the URL, e.g.

git clone gitlab.example.com:<my-project>.git

Solution

  • Considering the nature of GitLab groups, you need to put your repos into one dedicated group, say "global".

    gitlab.example.com:global/<my-repository>.git
    

    But: you can also reference those repos through a dedicated SSH URL named "globalGitLab", with a ~/.ssh/config file translating globalGitLab into git@gitlab.example.com with the right key.

    Host globalGitLab 
         HostName gitlab.example.com
         User git
         IdentityFile /path/to/right/id_rsa
    

    That alone would not fix your group issue: globalGitLab:myrepo.git would not work.

    However, you can also set the global Git configuration:

    git config --global url."globalGitLab:global/".insteadOf globalGitLab:
    

    (see "git config url.<base>.insteadOf ")

    That would translate any globalGitLab:myrepo (from your scripts) into globalGitLab:global/myrepo, which is compatible with what GitLab expects!