Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use git with ssh on github https repository addresses?

I want to clone some github repositories to computers that have only access to github via an SSH tunnel.

I can use the ssh addresses to clone simple repositories without problems.

When a repository contains submodules, the access method is controled by .gitsubmodules which often default to https addresses (since this is the recommended way by github).

Is there a way to tell git submodules that it should always use ssh access, even when the address of a submodule is an https address?

Having to clone a repo and modify its .gitsubmodules just to be able to clone it through an ssh tunnel seems retarded. Hardcoding the access method in a .gitsubmodules file instead of letting your users choose the appropiate method seems pretty retarded too. I guess there must be a better way but I cannot find it.

like image 540
gnzlbg Avatar asked Aug 05 '26 19:08

gnzlbg


1 Answers

You may use git to rewrite the urls

git config --global url."https://".insteadOf git://

You may include a hostname in the expression to restrict the rewrite to a specific host

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

If you do not whant the rewrite rules to be global then just add it to your local scope instead.

See more under section url.<base>.insteadOf at http://git-scm.com/docs/git-config

like image 189
joran Avatar answered Aug 07 '26 09:08

joran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!