当我试图在Windows上使用git Bash拉代码时,我有以下问题:

fatal: could not read Username for 'https://github.com': No such file or directory

我已经尝试实现这里提供的可接受的解决方案:

当推送提交Github时错误:致命:无法读取用户名

然而,问题仍然存在。

在添加/删除原点后,我仍然得到相同的错误。

你能给我一些建议吗?

谢谢!


当前回答

对我有用的是将Git存储库的访问权限从私有更改为公共。

其他回答

我在ssh jail (jailkit)中遇到了这个问题,其中/dev/tty不存在。我用jk_cp添加了这个设备文件,错误消失了。

我正在使用GitHub操作,其中作业被配置为完成任务。该解决方案适用于所有git命令执行环境发生变化的ci (Jenkins、Travis、Circle)。

job1: 使用github actions actions/checkout@v2使用个人访问令牌(PAT)检出存储库,作业成功完成,存储库克隆。

job2: 使用命令git Fetch——tags获取标签。由于同样的错误,作业失败

致命:无法读取用户名https://github.com':没有这样的文件或目录

失败原因:当作业发生变化时,命令运行环境也发生了变化,即使存储库存在,但需要提供github凭据来获取标记。

解决方案:在获取作业b2中的标记之前添加此命令

Git配置remote.origin.url 'https://${{your_personal_access_token}}@github.com/${{github。库}}’

注意:${{expression}}是github actions yaml syntex,用于发现环境变量/运行表达式。

对于那些在Jenkins管道中得到这个错误的人,可以使用SSH代理插件来修复。然后像这样包装你的git命令:

sshagent(['my-ssh-key']) {
    git remote set-url origin git@github.com:username/reponame.git
    sh 'git push origin branch_name'
}

按照步骤在这里设置SSH密钥:https://help.github.com/articles/generating-ssh-keys

OR

git remote add origin https://{username}:{password}@github.com/{username}/project.git

更新:如果你得到"fatal: remote origin already exists.",那么你必须使用set-url:

git remote set-url origin https://{username}:{password}@github.com/{username}/project.git
[SSH] executing...
fatal: could not read Username for 'https://github.com': No such device or address

[SSH] completed
[SSH] exit-status: 1

Build step 'Execute shell script on remote host using ssh' marked build as failure
Finished: FAILURE

索尔:- 如果存储库是私有的,它也属于另一个人或组织,并且你是该存储库的贡献者,那么你可以从Jenkins作业中运行git命令,它不会提示你输入用户名和密码。

https://username:token@github.com/accountname/reponame.git