Git: force to use SSH URL instead of HTTPS for github.com


#1

You can instruct git to use the SSH git clone url (git@...) instead of HTTPS one (https://) in every case.

Regardless of whether e.g. your CocoaPods spec includes the SSH or HTTPS github.com git clone url git will always use the SSH one (git@) this way. This can be useful if you use private submodules or CocoaPods spec/repos or any other tool which uses git and you want to force them to use SSH git clone URLs instead of HTTPS ones, as explained at: http://devcenter.bitrise.io/faq/adding-projects-with-submodules/

To reconfigure git to use SSH git clone URLs for github instead of HTTPS ones just run (e.g. using a Script step):

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

This instructs git that in every case when the git clone URL starts with https://github.com/ it should replace it with git@github.com: before contacting the server.

Note: this affects every git operation after running this git config, for github.com repos! It will always convert the URL and will use the SSH url instead for github.com repos.