简体   繁体   English

使用 npm 和 git 时遇到 ssh / https 问题

[英]Trouble with ssh / https while using npm and git

so I'm trying to use npm i --save-dev somePackage所以我正在尝试使用npm i --save-dev somePackage

but as I hit enter this shows up:但是当我点击进入时,它出现了:

/usr/local/bin/git ls-remote -h -t ssh://git@github.com/babel/preset-react.git
npm ERR! 
npm ERR! git@github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR! 
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in

I'm not quite sure whats happening here, I'm guessing using ssh and need a key but I don't want to do that and I want a regular push pull commit work flow so I guessing it would be https?我不太确定这里发生了什么,我猜想使用 ssh 并需要一个密钥,但我不想这样做,我想要一个常规的推拉提交工作流程,所以我猜它会是 https?

If thats the case how can I revert or delete and start a new?如果是这种情况,我该如何还原或删除并开始新的操作? I habe tried multiple commands and even githubs documentation but I can't seem to make it work?我已经尝试了多个命令甚至 githubs 文档,但我似乎无法让它工作?

UPDATE : found to change URL i need to do this command check first current url更新:发现要更改 URL 我需要执行此命令检查第一个当前 url

git remote -v 

then git remote set-url https://source/user/repo/.git然后git remote set-url https://source/user/repo/.git

but after doing that and typing in git remote -v nothing has changed?但是在这样做并输入git remote -v没有任何改变?

but after doing that and typing in git remote -v nothing has changed?但是在这样做并输入 git remote -v 之后没有任何改变?

That is because the correct command would be:那是因为正确的命令是:

git remote set-url origin https://source/user/repo/.git
                   ^^^^^^

But if you want to force npm to use HTTPS for all dependencies URLs, you can also use:但是如果你想强制 npm 对所有依赖 URL 使用 HTTPS,你也可以使用:

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM