Rebar3 / git not connecting to github.
When trying to setup a new Lisp Flavored Erlang project, I was going throught he usual steps of adding an erlang dependency to the rebar.config file. This fix isnt specific to LFE it applies to generic erlang too.
Here is the top of the rebar.config file:
{erl_opts, [debug_info]}. {deps, [ {lfe, "2.1.1"}, {ltest, "0.13.4"}, {lhc, ".*", {git,"https://github.com/lfex/lhc.git", {branch, "master"}}} ]}.
Whenever I'd ask rebar to get dependancies "rebar3 get-deps", i'd have rebar3 fail
✗ rebar3 get-deps ===> Verifying dependencies... ===> Fetching ljson (from {git,"git://github.com/lfex/ljson.git",{tag,"0.4.0"}}) ===> Failed to fetch and copy dep: {git,"git://github.com/lfex/ljson.git", {tag,"0.4.0"}}
Oddly, ssh works
✗ ssh -T git@github.com
Hi wmealing! You\'ve successfully authenticated, but GitHub does not provide shell access.
When trying to debug the issue, I tried to use git directly to clone the same project.
✗ git clone git://github.com/lfex/ljson.git Cloning into 'ljson'... fatal: unable to connect to github.com: github.com[0: 20.248.137.48]: errno=Operation timed out
So, it appears there is some kind of connection problem with git, sometimes I dont want to bother figuring out the problem because its usually something I can't fix because of decisions made outside my control.
I have noticed that git repositories that use the https:// protocol worked normally, whereas "git" over ssh was a problem. I can connect to multiple servers online via ssh and https, so I would immediately discount the network itself.
A sage friend of mine told me that git had a neat functionality documented in the git-config man page. This functionality is the "url.<base>.insteadOf" and is documented as "Any URL that starts with this value will be rewritten to start, instead, with <base>"
To solve our little dilemma, we can issue the following command:
$ git config --global url."https://".insteadOf git://
This rewrites the git request to use https:// instead of git:// in all future git requests, so now when rebar attempts to fetch dependancies:
✗ rebar3 get-deps ===> Fetching rebar3_lfe v0.4.4 ===> Fetching ljson (from {git,"git://github.com/lfex/ljson.git", {branch, "master"}})
Rebar mentions the 'old' url, but internally git will pivot to https://
The dependencies should be able to be fetched correctly.
Happy days.