Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to install specific branch of git repository using yarn?

Tags:

I am able to install one GitHub package but not other using yarn. Please let me know what could be the issue here.

I can add https://github.com/fancyapps/fancybox#3.0 but not https://github.com/opentripplanner/otp-react-redux#result-post-processor

ravis-MacBook-Pro:gitprojects ******$ mkdir test ravis-MacBook-Pro:gitprojects ******$ cd test ravis-MacBook-Pro:test ***********$ yarn init yarn init v1.6.0 question name (test):  question version (1.0.0):  question description:  question entry point (index.js):  question repository url:  question author:  question license (MIT):  question private:  success Saved package.json ✨  Done in 11.54s.  ravis-MacBook-Pro:test ******$ yarn add https://github.com/fancyapps/fancybox#3.0 yarn add v1.6.0 info No lockfile found. [1/4] πŸ”  Resolving packages... [2/4] 🚚  Fetching packages... [3/4] πŸ”—  Linking dependencies... warning " > @fancyapps/[email protected]" has unmet peer dependency "jquery@>=1.9.0". [4/4] πŸ“ƒ  Building fresh packages... success Saved lockfile. success Saved 1 new dependency. info Direct dependencies └─ @fancyapps/[email protected] info All dependencies └─ @fancyapps/[email protected] ✨  Done in 1.35s.   ravis-MacBook-Pro:test *******$ yarn add https://github.com/opentripplanner/otp-react-redux#result-post-processor yarn add v1.6.0 [1/4] πŸ”  Resolving packages... error Can't add "otp-react-redux": invalid package version undefined. info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command. ravis-MacBook-Pro:test *******$  
like image 580
Ravi Avatar asked Apr 24 '18 02:04

Ravi


People also ask

How do I download a specific branch?

While on a branch, clicking β€œDownload Zip” from the Code dropdown will lead you to a download for the specific branch you're on. It doesn't tell you this on the site though, so you'll have to make sure that the filename for the download URL matches the correct branch, named in reponame-branchname.

Can you git pull a specific branch?

To pull changes from a specific branch in Git, first, launch the β€œGit Bash” on your system. Next, move to the Git local repository using the β€œcd” command. After that, execute the β€œ$ git pull origin main” command to pull all changes from the origin and main branch and merge them in the local checked-out branch.

How do I add a specific version of yarn?

You can specify versions using one of these: yarn add package-name installs the β€œlatest” version of the package. yarn add [email protected] installs a specific version of a package from the registry. yarn add package-name@tag installs a specific β€œtag” (e.g. beta , next , or latest ).


2 Answers

You need use you git remote url and specify branch after hash(#).

yarn add https://github.com/opentripplanner/otp-react-redux.git#result-post-processor 

installs a package from a remote git repository at specific git branch, git commit or git tag.

yarn add <git remote url>#<branch/commit/tag>

enter image description here

like image 138
patelarpan Avatar answered Oct 04 '22 03:10

patelarpan


UPDATE

Please note that for Yarn 2+ you need to prefix the URL with package name:

yarn add otp-react-redux@https://github.com/opentripplanner/otp-react-redux#head=result-post-processor 
like image 39
Farzan Avatar answered Oct 04 '22 03:10

Farzan