使用curl通过CLI创建GitHub存储库时出现“凭据无效”的错误提示。

4
我正在尝试使用命令行创建一个GitHub仓库。
有人在这里建议可以使用以下命令:
curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO"}'
# Remember replace USER with your username and REPO with your repository/application name!
git remote add origin git@github.com:USER/REPO.git
git push origin master

当我使用它时,会提示我输入我的密码(我确定密码是正确的,因为我可以成功登录GitHub.com)。然后我收到这个错误:
c:\Development\Projects\MovieStar>curl -u 'jonnymaceachern' https://api.github.com/user/repos -d '{"name":"MovieStar"}'
Enter host password for user ''jonnymaceachern'':
{
  "message": "Bad credentials",
  "documentation_url": "http://developer.github.com/v3"
}

我尝试了在用户名周围不加引号,但是会出现“解析JSON时发生问题”的错误。

2个回答

1

git@github.com:USER/REPO.git是一个ssh url,而不是https url。
GitHub要求你输入“密码”,是因为ssh找不到你的公钥/私钥,和你的GitHub账户密码无关。

使用:

git remote add origin https://YourName@github.com/YourName/REPO.git
git push -u master

然后它会要求您输入http凭据。
如果您不想在每次交易时都输入它,请参见“在使用https://github时是否有跳过密码输入的方法”。


0

我的做法:

 curl -u 'USER:PASWORD' https://api.github.com/user/repos -d '{"name":"REPO"}'

在我的 Github 帐户上测试通过。这样,您就不会被提示输入密码。如果这样做不起作用,可能是因为您的密码不正确(或用户名不正确)。


仍然出现相同的错误。甚至登录GitHub更改密码并重试也无效。在用户名字段中使用我的电子邮件也不起作用。 - Jonny
这将在您的shell历史记录中留下密码。 OP的命令在这方面可能更好。 - aidan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接