Force git to use SSH on GitHub

I can use HTTPS and SSH URL's for GitHub repos, thanks to insteadOf

Written by Rico Sta. Cruz
(@rstacruz) · 9 June 2018

This forces GitHub to always use SSH, even for HTTPS URL’s! This way, you can use https:// GitHub URL’s and they will still use your SSH key.

Terminal window
git config --global url."".insteadOf ""

How it works

When cloning an HTTPS URL, it now gets rewritten as an SSH URL. It will instead be fetching from via SSH.

git clone
# ...actually clones

The inverse: Use HTTPS instead of SSH

Alternatively, this forces GitHub to always use HTTPS. Great for macOS, where you can use git-credential-osxkeychain to store your GitHub token. This will not rewrite URL’s, though, so I don’t really recommend it!

Terminal window
git config --global url."https://github".insteadOf git://github


Hat tip to these people!

Written by Rico Sta. Cruz

I am a web developer helping make the world a better place through JavaScript, Ruby, and UI design. I write articles like these often. If you'd like to stay in touch, subscribe to my list.


More articles

← More articles