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

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

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

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

然而,问题仍然存在。

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

你能给我一些建议吗?

谢谢!


当前回答

我通过清除无效缓存得到了答案,然后清洁构建帮助我。

选择“File > Invalidate Caches / Restart”,然后单击 “无效并重新启动”按钮。 选择Build > Clean Project,然后选择Build > Rebuild 项目。

其他回答

简短的回答:

git init
git add README.md
git commit -m "first commit"


git remote add origin https://github.com/{USER_NAME}/{REPOSITORY_NAME}.git
git push --set-upstream origin master

如果不是新的存储库,请忽略前三行。

长描述:

刚刚遇到了同样的问题,因为上面的答案对我没有帮助,我决定张贴这个对我有用的解决方案。

一些笔记:

日志含义生成SSH密钥 SSH密钥已添加到GitHub,仍然有此错误。 我在GitHub上为这个项目创建了一个新的存储库,并遵循了所描述的步骤

作为命令行工具,我使用GitShell(对于Windows,我使用Terminal)。Mac上的app)。 GitShell是GitHub官方工具,可以从https://windows.github.com/下载

这里什么都试过了,都没用。

然而,当我试图通过gitconfig——system——list进行调试时,我得到了致命的结果:无法读取配置文件'/etc/gitconfig':没有这样的文件或目录。

所以我做了以下的事情,

sudo ln -s $HOME/.gitconfig /etc/gitconfig

瞧,它起作用了。

下面是人们得到这个错误的简单原因:您试图从一个还没有设置本地git访问的回购中拉取。对我来说,当我将公共回购更改为私有回购时,我得到了这个错误。现在我很清楚,公共回购不需要认证,但私人回购需要。

希望这有助于澄清错误发生的原因以及该原因的潜在触发因素。

按照步骤在这里设置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

当试图克隆无效的HTTP URL时,也会发生此错误。例如,这是我在试图克隆一个GitHub URL时得到的错误,这是几个字符:

$ git clone -v http://github.com/username/repo-name.git
Cloning into 'repo-name'...
Username for 'https://github.com': 
Password for 'https://github.com': 
remote: Repository not found.
fatal: Authentication failed for 'https://github.com/username/repo-name.git/'

但是,它实际上发生在Emacs内部,所以Emacs中的错误看起来是这样的:

fatal: could not read Username for ’https://github.com’: No such device or address

因此,它没有给出一个有用的错误,告诉我那个URL上没有这样的回购,而是给了我这个错误,让我徒劳地追逐,直到我最终意识到URL是错误的。

这是git 2.7.4版本。

我在这里张贴这个,因为一个月前发生在我身上的事情,刚刚又发生了一次,让我再次陷入同样的徒劳。>:(