git - 由于 ssh 和 https 连接的私有(private) git 存储库,npm 安装失败

标签 git npm ssh package.json

我有以下 package.json 文件,我正在尝试运行 npm install,但它失败了。

    "test": "git+https://<TOKEN>@github.build.test.com/test.git",

我有与 github 匹配的 ssh key 。但是,即使我写了以下内容,它也始终使用 https 运行。

    "test": "git+ssh://git@github.build.test.com/test.git",

在这两种情况下,我都会遇到以下错误消息

npm ERR! Error while executing:
npm ERR! C:\Program Files\Git\cmd\git.EXE ls-remote -h -t https://github.build.test.com/test.git
npm ERR!
npm ERR! remote: Password authentication is not available for Git operations.
npm ERR! remote: You must use a personal access token or SSH key.
npm ERR! remote: See https://github.build.test.com/settings/tokens or https://github.build.test.com/settings/ssh
npm ERR! fatal: unable to access 'https://github.build.test.com/test.git/': The requested URL returned error: 403
npm ERR!
npm ERR! exited with error code: 128

如果我单独运行上面的命令,它会起作用。

git ls-remote -h -t https://<TOKEN>@github.build.test.com/test.git
git ls-remote -h -t ssh://git@github.build.test.com/test.git

我该如何解决?

谢谢

最佳答案

首先如果你有 url.<base>.insteadOf directive在你的 git 配置中:

cd /path/to/repo
git config -l|grep -i insteadOf

如果没有,请设置您自己的一个:

git config url."ssh://git@github.build.test.com".insteadOf  https://github.build.test.com

再看看是不是还在用https

关于git - 由于 ssh 和 https 连接的私有(private) git 存储库,npm 安装失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54016867/

相关文章:

node.js - 如何管理内部 Node.JS 模块

linux - XDebug 与 PhpStorm : Debugging a CLI script, 通过反向 SSH 隧道连接

git - Jenkins git 插件 - 有时太慢了

java - Apache Ant 有什么方法可以让构建忽略错误

npm install 无法执行 postinstall 脚本 bower install

bash - 期望别名

git - 无法将 EC2 实例的 ssh-key 添加到 bitbucket 帐户

git : How to get name of the branch tracked by the current one?

git 在带有 @ 符号的文件夹中添加文件 - fatal : Not a git repository

javascript - 我应该把 bower.json 放在哪里?