gitgithub

How to make GitHub desktop use ssh by default?


Sometimes I clone a repository on GitHub using the Open with GitHub Desktop functionality button as documented here on github . However, this functionality always by default clones using https instead of ssh.

So everytime I clone something I need to manually change the url. Is there a way to tell GitHub that I never want to clone with https and always want to clone with ssh?


Solution

  • Generic method (i.e. affecting all Git usage of GitHub repositories, not only the GitHub app):

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

    This will cause Git to automatically use an SSH address even if an HTTPS URL was given.

    Multiple prefixes can be aliased using config --add, e.g. I used to have a gh: prefix so that I could do git clone gh:foo/bar. (Wasn't very useful.)

    You can also use the pushInsteadOf option instead, so that the clone and pulls/fetches would still be done over HTTPS (faster connection establishment) while pushes will be done over SSH (using your public key).

    [url "git@github.com:"]
        pushInsteadOf = https://github.com/
        pushInsteadOf = git://github.com/
    
    [url "https://github.com/"]
        insteadOf = git://github.com/