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

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

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

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

然而,问题仍然存在。

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

你能给我一些建议吗?

谢谢!


当前回答

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

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

所以我做了以下的事情,

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

瞧,它起作用了。

其他回答

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

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

像这样替换你的远程url:

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

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

我正在使用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,用于发现环境变量/运行表达式。