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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22147574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:49:59  来源:igfitidea点击:

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

gitgithubgit-pullgit-bash

提问by noobie-php

I have the following problem when I try to pull code, using GIT Bash on windows

当我尝试在 Windows 上使用 GIT Bash 提取代码时遇到以下问题

I already tried to implement the accepted solution provided here:

我已经尝试实施此处提供的已接受解决方案:

but the problem persists. After adding/removing origin I still get the same error.

但问题仍然存在。添加/删除原点后,我仍然遇到相同的错误。

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

回答by Tony Zampogna

Follow the steps to setup SSH keys here: https://help.github.com/articles/generating-ssh-keys

按照此处的步骤设置 SSH 密钥:https: //help.github.com/articles/generate-ssh-keys

OR

或者

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

回答by Fayaz

I faced the exact same problem. This problem occurred when I cloned using HTTPS URL and then tried to push the changes using Git Bash on Windows using:

我遇到了完全相同的问题。当我使用 HTTPS URL 进行克隆,然后尝试使用 Windows 上的 Git Bash 推送更改时,会出现此问题:

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

However, when I used SSH URL to clone, this problem didn't occur:

但是,当我使用SSH URL进行克隆时,并没有出现这个问题:

git clone [email protected]:{username}/{repo}.git

回答by Rosdi Kasim

If you are getting this error instead :

如果您收到此错误:

fatal: could not read Username for 'https://github.com': No error

致命:无法读取“ https://github.com”的用户名:没有错误

Then you need to update your Git to version 2.16or later.

然后您需要将您的 Git 更新到版本2.16或更高版本。

回答by Katia

For me nothing worked from suggested above, I use git pullfrom jenkins shell script and apparently it takes wrong user name. I spent ages before I found a way to fix it without switching to SSH.

对我来说,上面的建议没有任何效果,我使用git pull了 jenkins shell 脚本,显然它使用了错误的用户名。我花了很长时间才找到一种无需切换到 SSH 即可修复它的方法。

In your the user's folder create .gitconfig file (if you don't have it already) and put your credentials in following format: https://user:[email protected], more info. After your .gitconfig file link to those credentials, in my case it was:

在您的用户文件夹中创建 .gitconfig 文件(如果您还没有)并将您的凭据放入以下格式:https://user:[email protected], more info。在您的 .gitconfig 文件链接到这些凭据后,在我的情况下是:

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

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

Now git will always use those credentials no matter what. I hope it will help someone, like it helped me.

现在 git 将始终使用这些凭据,无论如何。我希望它会帮助某人,就像它帮助了我一样。

回答by Louis Parkin

I found my answer here:

我在这里找到了答案:

edit ~/.gitconfigand add the following:

编辑~/.gitconfig并添加以下内容:

[url "[email protected]:"]
 insteadOf = https://github.com/

Although it solves a different problem, the error code is the same...

虽然它解决了不同的问题,但错误代码是相同的......

回答by blujay

This error can also happen when trying to clone an invalid HTTP URL. For example, this is the error I got when trying to clone a GitHub URL that was a few characters off:

尝试克隆无效的 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/'

It actually happened inside Emacs, though, so the error in Emacs looked like this:

不过,它实际上发生在 Emacs 内部,因此 Emacs 中的错误如下所示:

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

So instead of a helpful error saying that there was no such repo at that URL, it gave me that, sending me on a wild goose chase until I finally realized that the URL was incorrect.

因此,与其说那个 URL 上没有这样的 repo 有帮助的错误,它给了我这个错误,让我大吃一惊,直到我最终意识到 URL 是不正确的。

This is with git version 2.7.4.

这是 git 版本 2.7.4。

I'm posting this here because it happened to me a month ago and again just now, sending me on the same wild goose chase again. >:(

我在这里发布这个是因为它发生在我一个月前和刚刚发生在我身上,再次让我陷入同样的​​疯狂追逐。>:(

回答by spiralmoon

If you want to continue use https instead ssh, and avoid type into your username and password for security reason.

如果您想继续使用 https 而不是 ssh,并且出于安全原因避免输入您的用户名和密码。

You can also try Github OAuth token, then you can do git config remote.origin.url 'https://{token}@github.com/{username}/{project}.git'or git remote add origin 'https://{token}@github.com/{username}/{project}.git'

您也可以尝试Github OAuth token,然后您可以执行 git config remote.origin.url 'https://{token}@github.com/{username}/{project}.git'git remote add origin 'https://{token}@github.com/{username}/{project}.git'

This works for me!

这对我有用!

回答by Creative Magic

Short Answer:

简答:

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

Ignore first three lines if it's not a new repository.

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

Longer description:

更长的描述:

Just had the same problem, as non of the above answers helped me, I have decided to post this solution that worked for me.

刚刚遇到了同样的问题,因为上述答案都没有帮助我,所以我决定发布这个对我有用的解决方案。

Few Notes:

几点注意事项:

  • The SSH key was generated
  • SSH key was added to github, still had this error.
  • I've made a new repository on GitHub for this project and followed the steps described
  • SSH 密钥已生成
  • SSH 密钥已添加到 github,仍然出现此错误。
  • 我在 GitHub 上为这个项目创建了一个新的存储库,并按照描述的步骤操作

As the command line tool I used GitShell (for Windows, I use Terminal.app on Mac).
GitShell is official GitHub tool, can be downloaded from https://windows.github.com/

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

Hope this helps to anyone who has the same problem.

希望这对有同样问题的人有所帮助。

回答by David Burson

I fixed this by installing a newer version of Git. The version I installed is 2.10.2 from https://git-scm.com. See the last post here: https://www.bountysource.com/issues/31602800-git-fails-to-authenticate-access-to-private-repository-over-https

我通过安装更新​​版本的 Git 解决了这个问题。我安装的版本是https://git-scm.com 的2.10.2 。请参阅此处的最后一篇文章:https: //www.bountysource.com/issues/31602800-git-fails-to-authenticate-access-to-private-repository-over-https

With newer Git Bash, the credential manager window pops up and you can enter your username and password, and it works!

使用较新的 Git Bash,凭据管理器窗口会弹出,您可以输入您的用户名和密码,它可以工作!

回答by GrossesKinoZuerich

Replace your remote url like this:

像这样替换您的远程网址:

git remote set-url origin https://<username>@github.com/<username>/<repo>.git