git

Git clone with ssh address failed


I want to clone a git repo from Github with the command

git clone git@github.com:rgov/Thunderbolt3Unblocker.git

but I get

Cloning into 'Thunderbolt3Unblocker'...
fatal: unable to access 'https://github.com:rgov/Thunderbolt3Unblocker.git/': Port number ended with 'r'

It seem git interprets username "rgov" as port number?

The git version is 2.27.0


Solution

  • Check git config --global -l output for any insteadOf directive, like:

    git config --global url."https://github.com".insteadOf git@github.com
    

    That would explain why git@github.com whas replaced by https://github.com

    Note that this directive is not well written: it should have been:

    git config --global url."https://github.com/".insteadOf git@github.com:
                                              ^^^                        ^^^
    

    That would at least gave you a valid HTTPs URL:

    https://github.com/rgov/Thunderbolt3Unblocker.git
                     ^^^
    

    But if you want to use SSH, delete that insteadOf directive from your global git configuration.

    git config --global --unset-all url."https://github.com/".insteadof
    

    You can also