Skip to content

Instantly share code, notes, and snippets.

@sujeetkv
Last active May 6, 2024 07:10
Show Gist options
  • Save sujeetkv/383506c42f7580abdbeed47809b8814f to your computer and use it in GitHub Desktop.
Save sujeetkv/383506c42f7580abdbeed47809b8814f to your computer and use it in GitHub Desktop.
Use private repo as npm dependency.

Use private repo as npm dependency

Create Deploy-Token (Access-Token) for particular private repo and use it in dependency as following:

{
    "dependencies": {
        "package-name": "git+https://<username>:<access_token>@github.com/username/repository#{branch|tag}"
    }
}

For Example:

{
    "dependencies": {
        "demo-lib": "git+https://<username>:<access_token>@gitlab.com/username/demo-lib#1.2.4",
        "demo-util": "git+https://<username>:<access_token>@gitlab.com/username/demo-util#prod",
        "demo-dep": "git+https://<access_token>:x-oauth-basic@github.com/username/demo-dep#master"
    }
}

Or you can add SSH key of of git client and use following:

{
    "dependencies": {
        "package-name": "git+ssh://git@github.com:username/repository.git#{branch|tag}"
    }
}
@kodmanyagha
Copy link

In 2024 that url will generate a deprecation warning: git+ssh://git@github.com:username/repository.git#{branch|tag}

(node:4744) [DEP0170] DeprecationWarning: The URL ssh://git@github.com:username/repository.git is invalid. Future
versions of Node.js will throw an error.
(Use `node --trace-deprecation ...` to show where the warning was created)

You must replace colon with slash. Working line is exactly like that:

"package/name": "git+ssh://git@github.com/username/project-name.git#branch-or-commithash-or-tag"

Happy coding!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment