Install specific branch from github using Npm

GithubNpm Install

Github Problem Overview


I would like to install bootstrap-loader from github in my project using npm

Currently they are maintaining two version of this project which are comaptible with webpack version 1 and 2.

I would like to install version 1. What npm command I should use to install this?

I tried using below one but it is not working.

npm install git://github.com/shakacode/bootstrap-loader.git[#v1] --Save 

Github Solutions


Solution 1 - Github

There are extra square brackets in the command you tried.

To install the latest version from the brach-name branch, you can use:

npm install "https://github.com/shakacode/bootstrap-loader.git#branch-name" --save

Solution 2 - Github

npm: npm install username/repo#branchName --save

yarn: yarn add username/repo#branchName

e.g. npm i betimer/rtc-attach#master --save (my username is betimer)

// this will appear in your package.json:
"rtc-attach": "github:betimer/rtc-attach#master"

One thing I also want to mention: it's not a good idea to check in the package.json for the build server auto pull the change. Instead, put the npm i (first command) into the build command, and let server just install and replace the package.

One more note, if the package.json private is set to true, may impact sometimes.

Solution 3 - Github

you can give git pattern as version, yarn and npm are clever enough to resolve from a git repo.

yarn add any-package@user-name/repo-name#branch-name

or for npm

npm install --save any-package@user-name/repo-name#branch-name

Solution 4 - Github

Another approach would be to add the following line to package.json dependencies:

"package-name": "user/repo#branch"

For example:

"dependencies": {
    ... other dependencies ...

    "react-native": "facebook/react-native#master"
}

And then do npm install or yarn install

Solution 5 - Github

I'm using SSH to authenticate my GitHub account and have a couple dependencies in my project installed as follows:

"dependencies": {
  "<dependency name>": "git+ssh://[email protected]/<github username>/<repository name>.git#<release version | branch>"
}

Solution 6 - Github

Had to put the url in quotes for it work

npm install "https://github.com/shakacode/bootstrap-loader.git#v1" --save

Solution 7 - Github

Tried suggested answers, but got it working only with this prefix approach:

npm i github:user/repo.git#version --save -D

Solution 8 - Github

Only solution working for me:

$ npm i https://github.com/{USER}/{REPO}/tarball/{BRANCH} --save

as explained here.

Solution 9 - Github

The Doc of the npm defines that only tag/version can be specified after repo_url.

Here is the Doc: https://docs.npmjs.com/cli/install

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSachinView Question on Stackoverflow
Solution 1 - GithublestView Answer on Stackoverflow
Solution 2 - GithubXinView Answer on Stackoverflow
Solution 3 - GithubmkgView Answer on Stackoverflow
Solution 4 - GithubIlarion HalushkaView Answer on Stackoverflow
Solution 5 - GithubEsteban BoraiView Answer on Stackoverflow
Solution 6 - Githubuser2643679View Answer on Stackoverflow
Solution 7 - GithubArtjom KurapovView Answer on Stackoverflow
Solution 8 - GithubFruganView Answer on Stackoverflow
Solution 9 - GithubmenepetView Answer on Stackoverflow