当我试图在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时错误:致命:无法读取用户名
然而,问题仍然存在。
在添加/删除原点后,我仍然得到相同的错误。
你能给我一些建议吗?
谢谢!
当前回答
像这样替换你的远程url:
git remote set-url origin https://<username>@github.com/<username>/<repo>.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'
}
如果你的回购是私人的
而不是这种格式
https://github.com/username/<project_name>.git
使用这种格式
git@github.username/<project_name>.git
您可以在SSH选项下获得正确的url
去你的Github回购->点击代码->选择SSH ->复制你的回购URL
希望这能有所帮助。
我也面临着同样的问题。当我使用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密钥,这种方法也不能工作。
在我的情况下,我必须在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,用于发现环境变量/运行表达式。