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

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

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

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

然而,问题仍然存在。

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

你能给我一些建议吗?

谢谢!


当前回答

当试图克隆无效的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版本。

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

其他回答

我也面临着同样的问题。当我使用HTTPS URL克隆一个repo,然后尝试推送更改(在Linux/Mac上使用Shell或在Windows上使用Git Bash)时,出现了这个问题:

git clone https://github.com/{username}/{repo}.git

但是,当我使用SSH URL克隆时,这个问题没有发生:

git clone git@github.com:{username}/{repo}.git

如果你已经使用HTTPS克隆了repo,并且不想重做所有事情,你可以使用set-url将原始URL更改为SSH URL:

git remote set-url origin git@github.com:{username}/{repo}.git

注意:我有SSH密钥添加到我的GitHub帐户。如果没有设置SSH密钥,这种方法也不能工作。

对于我来说,上面建议的没有任何工作,我使用了Jenkins Shell Script中的git pull命令,显然它需要错误的用户名。我花了很长时间才找到一种不切换到SSH的方法来修复它。

在你的用户文件夹中创建。gitconfig文件(如果你还没有的话),并把你的凭证放在以下格式:https://user:pass@example.com,更多信息。在你的.gitconfig文件链接到这些凭证之后,在我的情况下,它是:

[credential]
   helper = store --file /Users/admin/.git-credentials

现在git无论如何都会使用这些凭证。我希望它能帮助别人,就像它帮助了我一样。

简短的回答:

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/下载

请检查以下内容

Android Studio ->首选项->版本控制-> Git ->使用凭据助手

从Android Studio终端执行git拉取 例如:test@test:~/StudioProjects/dummy-project-android$ git 添加用户名 例如:test@test:~/StudioProjects/dummy-project-android$ "username" 添加用户密码 “https://dummy-project-android@git.com”的密码:“Password”

之后,我们就可以进行剩下的手术了