当我试图在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时错误:致命:无法读取用户名
然而,问题仍然存在。
在添加/删除原点后,我仍然得到相同的错误。
你能给我一些建议吗?
谢谢!
当前回答
按照步骤在这里设置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
其他回答
如果你的回购是私人的
而不是这种格式
https://github.com/username/<project_name>.git
使用这种格式
git@github.username/<project_name>.git
您可以在SSH选项下获得正确的url
去你的Github回购->点击代码->选择SSH ->复制你的回购URL
希望这能有所帮助。
我在这里找到了答案:
编辑~ /。并添加以下内容:
[url "git@github.com:"]
insteadOf = https://github.com/
虽然它解决的问题不同,但错误代码是一样的…
[SSH] executing...
fatal: could not read Username for 'https://github.com': No such device or address
[SSH] completed
[SSH] exit-status: 1
Build step 'Execute shell script on remote host using ssh' marked build as failure
Finished: FAILURE
索尔:- 如果存储库是私有的,它也属于另一个人或组织,并且你是该存储库的贡献者,那么你可以从Jenkins作业中运行git命令,它不会提示你输入用户名和密码。
https://username:token@github.com/accountname/reponame.git
请检查以下内容
Android Studio ->首选项->版本控制-> Git ->使用凭据助手
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开始正常工作