Short Git Clones

Published:
Talks about: , , and

In case you don’t want to write git clone git@github.com:orga/repo.git all the time, consider using a custom SSH config (~/.ssh/config) like this:

Host github
    HostName github.com
    User git
    IdentityFile ~/.ssh/<KEY-FOR-GITHUB>

Host gitlab
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/<KEY-FOR-GITLAB>

Host bitbucket
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/<KEY-FOR-BITBUCKET>

Host codeberg
    HostName codeberg.org
    User git
    IdentityFile ~/.ssh/<KEY-FOR-CODEBERG>

Once configured, you can now write:

$ git clone github:orga/repo
$ git clone gitlab:orga/repo
$ git clone bitbucket:orga/repo
$ git clone codeberg:orga/repo

In case you are working with lots of repositories inside a single organization, consider adding the following git configuration ($XDG_CONFIG_HOME/git/config or ~/.gitconfig):

[url "github:orga/"]
  insteadOf = orga:
[url "gitlab:orga/"]
  insteadOf = orgl:
[url "bitbucket:orga/"]
  insteadOf = orgb:
[url "codeberg:orga/"]
  insteadOf = orgc:

Which allows you to just write:

$ git clone orga:repo
$ git clone orgl:repo
$ git clone orgb:repo
$ git clone orgc:repo

Git will substitute the insteadOf values like orga: with the configured url (e.g. github:orga/). The actual clone URL is github:orga/repo at this point, which can be used by Git together with the SSH config mentioned above to clone repositories.