执行Git子模块克隆时要求输入用户名密码的原因排查
问题描述
按照仓库指引执行以下命令:
git submodule update --init --recursive --remote
终端弹出认证提示及报错信息:
Cloning into '/Users/brandomiranda/proverbot9001/coq-projects/VST/coq-ext-lib/coqdocjs'... Username for 'https://github.com': brando90 Password for 'https://brando90@github.com': remote: Support for password authentication was removed on August 13, 2021. remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication. fatal: Authentication failed for 'https://github.com/coq-ext-lib/coqdocjs.git/' fatal: clone of 'https://github.com/coq-ext-lib/coqdocjs.git' into submodule path '/Users/brandomiranda/proverbot9001/coq-projects/VST/coq-ext-lib/coqdocjs' failed Failed to clone 'coqdocjs'. Retry scheduled Cloning into '/Users/brandomiranda/proverbot9001/coq-projects/VST/coq-ext-lib/templates'... Username for 'https://github.com': Password for 'https://github.com': remote: Repository not found. fatal: Authentication failed for 'https://github.com/coq-ext-lib/templates.git/' fatal: clone of 'https://github.com/coq-ext-lib/templates.git' into submodule path '/Users/brandomiranda/proverbot9001/coq-projects/VST/coq-ext-lib/templates' failed Failed to clone 'templates'. Retry scheduled Cloning into '/Users/brandomiranda/proverbot9001/coq-projects/VST/coq-ext-lib/coqdocjs'... Username for 'https://github.com': Password for 'https://github.com': remote: Repository not found. fatal: Authentication failed for 'https://github.com/coq-ext-lib/coqdocjs.git/' fatal: clone of 'https://github.com/coq-ext-lib/coqdocjs.git' into submodule path '/Users/brandomiranda/proverbot9001/coq-projects/VST/coq-ext-lib/coqdocjs' failed Failed to clone 'coqdocjs' a second time, aborting fatal: Failed to recurse into submodule path 'coq-projects/VST/coq-ext-lib'
疑问:
- 这种情况是否正常?
- 为何Git会要求输入用户名和密码?
- 无法正常拉取并初始化子模块的原因是什么?
解答
1. 这种情况完全不正常
正常拉取公开子模块无需手动输入认证信息,出现报错说明拉取流程存在明确问题。
2. Git要求输入用户名密码的原因
- 子模块配置的是HTTPS协议仓库地址,Git拉取HTTPS地址仓库时,默认会触发认证流程(即使仓库是公开的,部分环境也会弹出认证提示)。
- GitHub在2021年8月就已取消密码认证方式,因此即使输入密码也会认证失败。
3. 无法拉取子模块的核心原因
- 仓库地址无效:报错中
remote: Repository not found提示明确说明coq-ext-lib/coqdocjs和coq-ext-lib/templates这两个仓库不存在,可能是仓库已删除、名称变更,或是子模块配置的地址有误。 - 认证方式过时:即便仓库存在,使用密码认证HTTPS地址的方式已被GitHub禁用,必须改用个人访问令牌(PAT)或SSH协议才能完成认证。
修复建议
- 检查子模块配置:进入
coq-projects/VST/coq-ext-lib目录,查看.gitmodules文件中的子模块地址是否正确,确认对应仓库是否仍存在于GitHub。 - 切换认证方式:将HTTPS地址替换为SSH地址(需提前配置GitHub SSH密钥),或生成个人访问令牌(PAT),在Git提示输入密码时填入PAT而非账户密码。
- 反馈问题给维护者:如果是原仓库的子模块配置有误,建议在仓库的issue区提交反馈,确认正确的子模块依赖地址。
内容的提问来源于stack exchange,提问作者Charlie Parker
相关产品推荐
相关产品推荐

