Just the other day I found myself logging into my personal GitLab just to fetch a URL for git clone. I figured I could make a shell alias, but it seems that Git has something neat that works just as well. To clone a personal project, I just need to type: gcl my:<project>.

To set up the above, one only need a small Git configuration. A simple shell alias is used for convenience. In man git-config there is the following:

url.<base>.insteadOf Any URL that starts with this value will be rewritten to start, instead, with <base>. In cases where some site serves a large number of repositories, and serves them with multiple access methods, and some users need to use different access methods, this feature allows people to specify any of the equivalent URLs and have Git automatically rewrite the URL to the best alternative for the particular user, even for a never-before-seen repository on the site. When more than one insteadOf strings match a given URL, the longest match is used.

Note that any protocol restrictions will be applied to the rewritten URL. If the rewrite changes the URL to use a custom protocol or remote helper, you may need to adjust the protocol.*.allow config to permit the request. In particular, protocols you expect to use for submodules must be set to always rather than the default of user. See the description of protocol.allow above.

This means all that is needed in .gitconfig is:

[url "ssh://user@git.example.com:1234/path/"]
    insteadOf = "my:"

And to complement it, an alias for the rc-file:

alias gcl="git clone"

Using the shorthand for the URL will result in the full URL to be stored in the repository its cloned remotes:

❯ git remote -v
*
origin  ssh://user@git.example.com:1234/path/<project> (fetch)
origin  ssh://user@git.example.com:1234/path/<project> (push)

This small configuration should save some time and eliminates the need to copy-paste repository URLs.