当我尝试在 Windows 上使用 Git Bash 拉取代码时,出现了以下问题:
fatal: could not read Username for 'https://github.com': No such file or directory
我已经尝试实施这里提供的被接受的解决方案:
然而问题仍然存在。
在添加/删除源之后,我仍然遇到相同的错误。
能否就此问题提供建议?
谢谢!
当我尝试在 Windows 上使用 Git Bash 拉取代码时,出现了以下问题:
fatal: could not read Username for 'https://github.com': No such file or directory
我已经尝试实施这里提供的被接受的解决方案:
然而问题仍然存在。
在添加/删除源之后,我仍然遇到相同的错误。
能否就此问题提供建议?
谢谢!
请按照以下步骤设置SSH密钥:https://help.github.com/articles/generating-ssh-keys
或者
git remote add origin https://{username}:{password}@github.com/{username}/project.git
git remote set-url origin https://{username}:{password}@github.com/{username}/project.git
git remote set-url origin https://{username}:{password}@github.com/...
命令来更改 URL,而不是删除并重新添加源。 - Chrisgit remote -v
来读取密码。 - Jefferson Silva我遇到了完全相同的问题。当我使用 HTTPS URL
克隆一个仓库,然后尝试推送更改时,出现了这个问题(在 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
克隆了代码库,而且不想重新克隆,您可以使用 set-url
将远程仓库的 URL 改为 SSH URL
:
git remote set-url origin git@github.com:{username}/{repo}.git
注意: 我已经在我的GitHub帐户上添加了SSH密钥。 如果没有设置SSH密钥,则此方法也将不起作用。
顺便说一句,
git clone
或pull
应该可以正常工作,无需进行任何更改。只有当您在clone
之后使用git push
时才需要这些更改。
python:3.7-slim
,因此与Windows无关。 - Martin Thoma我在这里找到了答案:
编辑~/.gitconfig
,并添加以下内容:
[url "git@github.com:"]
insteadOf = https://github.com/
虽然它解决的问题不同,但错误代码是相同的...
请查看以下内容
Android Studio -> 首选项 -> 版本控制 -> Git -> 使用凭据助手
对于我来说,以上建议都没有起作用,我在Jenkins Shell脚本中使用git pull
命令,但显然它使用了错误的用户名。在我找到一种不需要切换到SSH的方法之前,我花费了很长时间。
在您的用户文件夹中创建.gitconfig文件(如果您还没有),并以以下格式输入您的凭据:https://user:pass@example.com
,更多信息。在您的.gitconfig文件中链接到这些凭据,对我来说是这样:
[credential]
helper = store --file /Users/admin/.git-credentials
现在git将始终使用这些凭据,无论如何。我希望它能帮助某人,就像它帮助了我一样。
[credential] helper = store --file /..../.git-credentials
放入.git/config
时,它才对我起作用。 - Kirill Oficerovgit config remote.origin.url 'https://{token}@github.com/{username}/{project}.git'
git remote add origin 'https://{token}@github.com/{username}/{project}.git'
fatal: could not read Username for 'https://github.com': No error
那么您需要将Git更新到版本2.16
或更高版本。
当尝试克隆无效的HTTP URL时,也会出现此错误。例如,当我尝试克隆一个GitHub URL时,由于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的repo,它直接让我这样干,一直找寻下去,最后才意识到URL不正确。
这是使用git 2.7.4时出现的情况。
我在此发布此信息,因为一个月前它发生过,并且刚刚再次出现,导致我再次陷入了同样的困境。 >:(
TL;DR:检查是否可以读写/dev/tty
。如果不能,并且您已使用su
打开shell,请检查是否正确使用了它。
我在Linux上遇到了同样的问题,但找到了解决办法。我没有存储我的凭据,所以我总是在提示符上输入它们:
Username for 'https://github.com': foo
Password for 'https://foo@github.com':
/usr/lib/git-core/git-remote-https
。您可以在此处查看strace:stat("/usr/lib/git-core/git-remote-https", {st_mode=S_IFREG|0755, st_size=1366784, ...}) = 0
pipe([9, 10]) = 0
rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f65398bb350) = 18177
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
close(10) = 0
read(9, "", 8) = 0
close(9) = 0
close(5) = 0
close(8) = 0
dup(7) = 5
fcntl(5, F_GETFL) = 0 (flags O_RDONLY)
write(6, "capabilities\n", 13) = 13
fstat(5, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
read(5, "fetch\noption\npush\ncheck-connecti"..., 4096) = 38
write(6, "option progress true\n", 21) = 21
read(5, "ok\n", 4096) = 3
write(6, "option verbosity 1\n", 19) = 19
read(5, "ok\n", 4096) = 3
stat(".git/packed-refs", {st_mode=S_IFREG|0664, st_size=675, ...}) = 0
lstat(".git/objects/10/52401742a2e9a3e8bf068b115c3818180bf19e", {st_mode=S_IFREG|0444, st_size=179, ...}) = 0
lstat(".git/objects/4e/35fa16cf8f2676600f56e9ba78cf730adc706e", {st_mode=S_IFREG|0444, st_size=178, ...}) = 0
dup(7) = 8
fcntl(8, F_GETFL) = 0 (flags O_RDONLY)
close(8) = 0
write(6, "list for-push\n", 14) = 14
read(5, fatal: could not read Username for 'https://github.com': No such device or address
"", 4096) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=18177, si_uid=1000, si_status=128, si_utime=6, si_stime=2} ---
exit_group(128) = ?
+++ exited with 128 +++
于是我试图直接调用它:
echo "list for-push" | strace /usr/lib/git-core/git-remote-https my
结果如下:
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 1 ([{fd=3, revents=POLLIN|POLLRDNORM}])
recvfrom(3, "\27\3\3\1\32", 5, 0, NULL, NULL) = 5
recvfrom(3, "\307|4Q\21\306\334\244o\237-\230\255\336\25\215D\257\227\274\r\330\314U\5\17\217T\274\262M\223"..., 282, 0, NULL, NULL) = 282
openat(AT_FDCWD, "/dev/tty", O_RDONLY) = -1 ENXIO (No such device or address)
openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=2995, ...}) = 0
read(4, "# Locale name alias data base.\n#"..., 4096) = 2995
read(4, "", 4096) = 0
close(4) = 0
openat(AT_FDCWD, "/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, "fatal: could not read Username f"..., 83fatal: could not read Username for 'https://github.com': No such device or address
) = 83
exit_group(128) = ?
+++ exited with 128 +++
然后我意识到:
openat(AT_FDCWD, "/dev/tty", O_RDONLY) = -1 ENXIO (No such device or address)
...
write(2, "fatal: could not read Username f"..., 83fatal: could not read Username for 'https://github.com': No such device or address
) = 83
git-remote-https
会尝试通过 /dev/tty
读取凭据信息,因此我尝试了一下它是否有效:
$ echo ahoj > /dev/tty
bash: /dev/tty: No such device or address
# echo ahoj > /dev/tty
ahoj
我知道我使用了su
来切换用户,于是我退出了shell并查看了一下,发现我使用了su danman -
命令,于是我再次测试:
~# su danman -
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
/root$ echo ahoj > /dev/tty
bash: /dev/tty: No such device or address
su - danman
后,一切正常运行:~# su - danman
danman@speedy:~$ echo ahoj > /dev/tty
ahoj
随后,Git开始正常工作了。
尝试了这里的所有方法,但仍然无法解决问题。
不过,当我尝试通过git config --system --list
进行调试时,出现了fatal: unable to read config file '/etc/gitconfig': No such file or directory
。
因此,我进行了以下操作,
sudo ln -s $HOME/.gitconfig /etc/gitconfig
然后,瞧,它就能工作了。
git config --global user.name "Your Name Here"
- Raul Andres