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

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

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

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

然而,问题仍然存在。

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

你能给我一些建议吗?

谢谢!


这是系统凭据缓存中存储的凭据的问题。你可能有配置变量“credential”。Helper '设置为wincred或winstore,它无法清除它。如果启动控制面板并启动凭据管理器applet,那么在标记为git:https://github.com的通用凭据部分中寻找项目。如果您删除了这些,那么下次将重新创建,但是凭据帮助实用程序将要求您提供新的凭据。


按照步骤在这里设置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

简短的回答:

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


我也面临着同样的问题。当我使用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密钥,这种方法也不能工作。


如果你想继续使用https代替ssh,出于安全考虑,不要输入你的用户名和密码。

你也可以试试Github OAuth令牌,然后你就可以了 Git配置remote.origin.url 'https://{token}@github.com/{username}/{project}.git' 或 Git远程添加原点“https://{token}@github.com/{username}/{project}.git”

这对我很管用!


像这样替换你的远程url:

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

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

在更新的Git Bash中,凭证管理器窗口会弹出,您可以输入您的用户名和密码,它就可以工作了!


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

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


注意,如果你得到这个错误:

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

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


尝试使用普通的Windows shell,如CMD。


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

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

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

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


我在这里找到了答案:

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

[url "git@github.com:"]
 insteadOf = https://github.com/

虽然它解决的问题不同,但错误代码是一样的…


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开始正常工作


对于那些在Jenkins管道中得到这个错误的人,可以使用SSH代理插件来修复。然后像这样包装你的git命令:

sshagent(['my-ssh-key']) {
    git remote set-url origin git@github.com:username/reponame.git
    sh 'git push origin branch_name'
}

早些时候,当我没有获得访问回购的权限时,我还将SSH pubkey添加到gitlab。在这一点上,我可以访问回购和运行去mod供应商,同样的问题发生了。(可能是因为缓存)

go mod vendor

go: errors parsing go.mod:
/Users/macos/Documents/sample/go.mod:22: git ls-remote -q https://git.aaa.team/core/some_repo.git in /Users/macos/go/pkg/mod/cache/vcs/a94d20a18fd56245f5d0f9f1601688930cad7046e55dd453b82e959b12d78369: exit status 128:
    fatal: could not read Username for 'https://git.aaa.team': terminal prompts disabled

经过一段时间的尝试,我决定删除SSH密钥和终端提示填写用户名和密码。那么一切都好了!


对我有用的是将Git存储库的访问权限从私有更改为公共。


仔细检查存储库URL, Github将提示您登录,如果回购不存在。

我猜这可能是为了检查你是否有私人回购权。可能是为了让私人回购更难列举。但这都是猜测。/耸耸肩


在我的情况下,我必须在GitHub下设置“个人访问令牌”:

设置-> developer设置 并启用SSO。


我正在使用GitHub操作,其中作业被配置为完成任务。该解决方案适用于所有git命令执行环境发生变化的ci (Jenkins、Travis、Circle)。

job1: 使用github actions actions/checkout@v2使用个人访问令牌(PAT)检出存储库,作业成功完成,存储库克隆。

job2: 使用命令git Fetch——tags获取标签。由于同样的错误,作业失败

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

失败原因:当作业发生变化时,命令运行环境也发生了变化,即使存储库存在,但需要提供github凭据来获取标记。

解决方案:在获取作业b2中的标记之前添加此命令

Git配置remote.origin.url 'https://${{your_personal_access_token}}@github.com/${{github。库}}’

注意:${{expression}}是github actions yaml syntex,用于发现环境变量/运行表达式。


[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


我在ssh jail (jailkit)中遇到了这个问题,其中/dev/tty不存在。我用jk_cp添加了这个设备文件,错误消失了。


这里什么都试过了,都没用。

然而,当我试图通过gitconfig——system——list进行调试时,我得到了致命的结果:无法读取配置文件'/etc/gitconfig':没有这样的文件或目录。

所以我做了以下的事情,

sudo ln -s $HOME/.gitconfig /etc/gitconfig

瞧,它起作用了。


请检查以下内容

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”

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


我通过清除无效缓存得到了答案,然后清洁构建帮助我。

选择“File > Invalidate Caches / Restart”,然后单击 “无效并重新启动”按钮。 选择Build > Clean Project,然后选择Build > Rebuild 项目。


下面是人们得到这个错误的简单原因:您试图从一个还没有设置本地git访问的回购中拉取。对我来说,当我将公共回购更改为私有回购时,我得到了这个错误。现在我很清楚,公共回购不需要认证,但私人回购需要。

希望这有助于澄清错误发生的原因以及该原因的潜在触发因素。


这里有一个简单的技巧

Android studio ->设置->版本控制-> git ->使用凭据助手

玩得开心


如果你的回购是私人的

而不是这种格式

https://github.com/username/<project_name>.git

使用这种格式

git@github.username/<project_name>.git

您可以在SSH选项下获得正确的url

去你的Github回购->点击代码->选择SSH ->复制你的回购URL

希望这能有所帮助。