当我试图在Windows上使用git Bash拉代码时,我有以下问题:
fatal: could not read Username for 'https://github.com': No such file or directory
我已经尝试实现这里提供的可接受的解决方案:
当推送提交Github时错误:致命:无法读取用户名
然而,问题仍然存在。
在添加/删除原点后,我仍然得到相同的错误。
你能给我一些建议吗?
谢谢!
当我试图在Windows上使用git Bash拉代码时,我有以下问题:
fatal: could not read Username for 'https://github.com': No such file or directory
我已经尝试实现这里提供的可接受的解决方案:
当推送提交Github时错误:致命:无法读取用户名
然而,问题仍然存在。
在添加/删除原点后,我仍然得到相同的错误。
你能给我一些建议吗?
谢谢!
当前回答
TL;DR:检查是否可以读写/dev/ ty.如果没有,并且已经使用su打开shell,请检查是否使用正确。
我也遇到了同样的问题,但在Linux上,我发现了这个问题。我没有存储我的证书,所以我总是在提示时输入它们:
Username for 'https://github.com': foo
Password for 'https://foo@github.com':
git处理http(s)连接的方式是使用/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开始正常工作
其他回答
仔细检查存储库URL, 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/下载
在我的情况下,我必须在GitHub下设置“个人访问令牌”:
设置-> developer设置 并启用SSO。
对于我来说,上面建议的没有任何工作,我使用了Jenkins Shell Script中的git pull命令,显然它需要错误的用户名。我花了很长时间才找到一种不切换到SSH的方法来修复它。
在你的用户文件夹中创建。gitconfig文件(如果你还没有的话),并把你的凭证放在以下格式:https://user:pass@example.com,更多信息。在你的.gitconfig文件链接到这些凭证之后,在我的情况下,它是:
[credential]
helper = store --file /Users/admin/.git-credentials
现在git无论如何都会使用这些凭证。我希望它能帮助别人,就像它帮助了我一样。