I'm trying to install github private repository by npm that includes other private github repositories as dependency.
Have tried a lot of ways and posts but none is working. Here is what i'm doing :
npm install git+https://github.com/myusername/mygitrepository.git
in package.json is like :
"dependencies": {
"repository1name": "git+https://github.com/myusername/repository1.git",
"repository2name": "git+https://github.com/myusername/repository2.git"
}
What is the the right way to do it?
There are multiple ways to do it as people point out, but the shortest versions are:
e.g.
Since Git uses
curl
under the hood, you can use~/.netrc
file with the credentials. For GitHub it would look something like this:If you choose to use
access tokens
, it can be generated from:This should also work if you are using Github Enterprise in your own corporation. just put your enterprise github url in the
machine
field.The accepted answer works, but I don't like much the idea to paste secure tokens into the
package.json
I have found it elsewhere, just run this one-time command as documented in the git-config manpage.
GITHUB_TOKEN
may be setup as environmnet variable or pasted directlyand then I install private github repos like:
npm install user/repo --save
works also in Heroku, just setup the above
git config ...
command asheroku-prebuild
script inpackage.json
and setupGITHUB_TOKEN
as Heroku config variable.For those of you who came here for public directories, from the npm docs: https://docs.npmjs.com/files/package.json#git-urls-as-dependencies
Git URLs as Dependencies
Git urls can be of the form:
The commit-ish can be any tag, sha, or branch which can be supplied as an argument to git checkout. The default is master.
For my private repository reference I didn't want to include a secure token, and none of the other simple (i.e. specifying only in package.json) worked. Here's what did work:
or just
https://docs.npmjs.com/files/package.json#github-urls