You have the following methods for connecting to a private gitlab repository
With SSH
git+ssh://[email protected]:Username/Repository#{branch|tag}
git+ssh://[email protected]/Username/Repository#{branch|tag}
With HTTPS
git+https://[email protected]/Username/Repository#{branch|tag}
With HTTPS and deploy token
git+https://<token-name>:<token>@gitlab.com/Username/Repository#{branch|tag}
Update
As @felix mentioned in comments (thanks @felix) using deploy token
is much more relevant for reading a private registry on gitlab
. This way is the token is compromised, attacker just can read that repository and cannot make changes.
Creating a Deploy Token
GitLab
account.Expand
on Deploy Tokens section.read_repository
Old answer
Goto User Settings > Access Tokens
and create a new access token
with read_registry
permission.
Copy generated token
, we need it for our package.json
file.
Now in package.json
add the dependency
as below:
"my-module": "git+https://Xaqron:[email protected]/Xaqron/my-module"
Replace Xaqron
with your username and token
with the generated token. You can specify branch
and tag
at the end of url by #{branch|tag}
.
Note: Since access token is located in package.json
anyone who has access to this project can read the repository, so I assume your project is private itself.
Instead of git://
, use git+ssh://
and npm should do the right thing.
Although the question is about Gitlab, this question is quite well ranked in google search, so here is some more information about how to fix a similar issue I got with Github.
For me, only changing the url didnt make it work. Here are the steps I had to take to fix this :
git+ssh://[email protected]:owner/repo.git#master
~/.ssh/config
create the file if it doesnt exist) to force the use of the DeployKey instead of the default ssh keyAfter that the npm install simply worked. All the other options and solutions resulted of the npm install breaking
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With