17

At work we are behind an HTTP Proxy and the git protocol (port 9418) is denied. My project has NPM dependencies and some of these dependencies have dependencies that use the git protocol, for instance:

In my package.json

"dependencies": {
    "jsdoc3" : "git+https://github.com/jsdoc3/jsdoc.git"
}

and the package.json of jsdoc3:

"dependencies": {
    "crypto-browserify": "git://github.com/dominictarr/crypto-browserify.git#95c5d505",
    "github-flavored-markdown": "git://github.com/hegemonic/github-flavored-markdown.git"
}

How can I get those dependencies, how to tell NPM to use git+https:// protocol instead of git:// protocol or to be able to use the git protocol?

To simplify things I'm on windows (it would be easier on Linux to create an SSH tunnel), and I use GIT-Bash.

Thanks

krampstudio
  • 3,519
  • 2
  • 43
  • 63

6 Answers6

40

You can tell git to use https instead of git:// with the following command:

git config --global url."https://".insteadOf git://
Nowres Rafed
  • 1,088
  • 10
  • 14
5

Finally I found a dirty solution, but that works fine. I've modified the code of NPM to replace the git protocol by the http protocol (thanks to opened source)

On npm v1.1.69, into the file npm/lib/cache.js, I've added the following lines to the function addRemoteGit

 // ssh paths that are scp-style urls don't need the ssh://
 if (parsed.pathname.match(/^\/?:/)) {
   u = u.replace(/^ssh:\/\//, "")
 }

 //begin trick
 if(/^git:/.test(u)){
     u = u.replace(/^git/, 'https');
 }
 //end trick

 log.verbose("addRemoteGit", [u, co])
krampstudio
  • 3,519
  • 2
  • 43
  • 63
  • 2
    I've also found this http://stackoverflow.com/questions/4891527/git-protocol-blocked-by-company-how-can-i-get-around-that/10729634#10729634 – krampstudio Feb 20 '13 at 12:39
  • thanks, the url rewrite wasn't working behind my work proxy, but this did. – Ed_ Oct 21 '13 at 11:13
  • I had to also change the `git:` to `https:` in this file: `npm/node_modules/github-url-from-username-repo/index.js`, but you got me on the right track to fixing the same issue. Thanks! – quornian May 20 '14 at 19:47
4

There are two git commands that are suggested in the npm wiki (reference: npm uses git:// and ssh+git:// only by default).

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://
Trent
  • 335
  • 2
  • 8
2

In addition to @Nowres suggestion, I had to do the following to get it to work

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://
Damilola
  • 1,014
  • 2
  • 20
  • 22
2

npm ci kept trying to use ssh://, so I had to do the following:

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf ssh://
Rafał Cieślak
  • 972
  • 1
  • 8
  • 25
1

It is possible to specify git+https:// or git+http:// in your dependency URLs

I took the following package.json from

{
  "name": "Sample package",
  "description": "Pacake for a Stackoverflow question",
  "author": "rk <rk@example.sampletld>",
  "dependencies": {
    "crypto-browserify": "git+https://github.com/dominictarr/crypto-browserify.git#95c5d505",
    "github-flavored-markdown": "git+https://github.com/hegemonic/github-flavored-markdown.git"
  },
  "engine": "node 0.4.1"
}

I then ran npm install and the node_modules contained the following

C:\Users\myself\node\node_modules>dir
 Volume in drive C is WINDOWS
 Volume Serial Number is 6E7A-96BE

 Directory of C:\Users\myself\node\node_modules

18/02/2013  13:57    <DIR>          .
18/02/2013  13:57    <DIR>          ..
18/02/2013  13:58    <DIR>          .bin
18/02/2013  13:57    <DIR>          crypto-browserify
18/02/2013  13:56    <DIR>          express
18/02/2013  13:57    <DIR>          github-flavored-markdown
18/02/2013  13:56    <DIR>          optimist
               0 File(s)              0 bytes
               7 Dir(s)  31,641,919,488 bytes free

C:\Users\myself\node\node_modules>

I tried this with both protocols git+http and git+https and the both worked, but bare http failed to work producing errors.

Rob Kielty
  • 7,958
  • 8
  • 39
  • 51
  • I don't have the control on the package.json file of the dependencies. In my package.json, all my dependencies use the `git+https` scheme, but the problem is for the transitives dependencies (the dependencies of my dependencies). – krampstudio Feb 18 '13 at 14:15
  • Ah I see; It shouldn't be impossible to to setup an SSH tunnel a windows environment there are tools to do that. Failing that you could hack your immediate dependencies to use the +http variants. An awful hack though for sure. Finally there is the option to make a business case for the project and present that to your network manager to allow the git traffic. – Rob Kielty Feb 18 '13 at 14:19