Xinrui Ma
Xinrui Ma

Reputation: 2105

How to use another git repo as my existing repo's dependency

Say I have an existing git repo I am working on named - b2c, give it an URL https://github.com/XXX/angular-portal-b2c.git

I have another git repo called b2c-library, which contains the useful pre-build library. URL: https://github.com/XXX/angular-portal-library.git

I want to be able to use b2c-library in my b2c project, just like a dependency, which in node_modules, it should have a folder called b2c-library.

What steps should I follow?

Thanks.

As I said, it should just like a dependency which should appear in your node_modules. when you do npm install, the b2c-library should be installed in node_modules, git status should not track anything you did in b2c-library even you are in that repo.

Upvotes: 0

Views: 1267

Answers (1)

Mark Adelsberger
Mark Adelsberger

Reputation: 45819

So you want this to work like a node dependency... that seems much more like an npm question than a git question.

In your package.json you can specify the library as a dependency, using the git URL in place of the normal version string. See the relevant npm documentation at https://docs.npmjs.com/files/package.json

Or, if you don't want to have to maintain the version relationship via the commit-ish in the URL, you can package the lib and put it in a private NPM registry. In that case, you of course have to load updated versions of the lib into the registry before the other package can "see" it.

Upvotes: 1

Related Questions