如何修复WSL Ubuntu中Git Credential Manager的Exec Format Error
解决WSL2中调用Windows Git Credential Manager的Exec format error问题
问题背景
在WSL2的Ubuntu环境中配置Git时,调用Windows的Git Credential Manager出现如下错误:
/mnt/c/Program\ Files/Git/mingw64/bin/git-credential-manager.exe get: 1: /mnt/c/Program Files/Git/mingw64/bin/git-credential-manager.exe: Exec format error
重启WSL后仅能正常执行1-2次,随后错误复现。
当前WSL的Git配置:
[credential "https://dev.azure.com"] useHttpPath = true [credential] helper = /mnt/c/Program\\ Files/Git/mingw64/bin/git-credential-manager.exe
Windows端Git配置:
[credential] azreposCredentialType = oauth msauthUseBroker = true msauthUseDefaultAccount = true [credential "redacted"] azureAuthority = [login site] username = [myemail] [credential "https://dev.azure.com"] useHttpPath = true
解决方法
方法1:通过wsl.exe间接调用Windows的GCM
直接在WSL中执行Windows exe文件可能存在执行格式或interop稳定性问题,改用wsl.exe中转调用:
- 执行命令修改全局配置:
git config --global credential.helper '!wsl.exe "C:\\Program Files\\Git\\mingw64\\bin\\git-credential-manager.exe"' - 或手动编辑
~/.gitconfig,替换credential.helper行:[credential] helper = !wsl.exe "C:\\Program Files\\Git\\mingw64\\bin\\git-credential-manager.exe"
方法2:安装Linux版Git Credential Manager
完全使用WSL内的凭证管理工具,避免跨系统调用:
- 安装GCM:
curl -s https://packagecloud.io/install/repositories/git-core/git-credential-manager/script.deb.sh | sudo bash sudo apt-get install git-credential-manager-core - 配置Git使用该helper:
git config --global credential.helper manager-core
方法3:修复WSL Interop配置
确保WSL与Windows的互操作功能正常启用:
- 创建或编辑
/etc/wsl.conf:[interop] enabled=true appendWindowsPath=true - 在Windows终端执行
wsl --shutdown,重启WSL后生效。
内容的提问来源于stack exchange,提问作者wyapa
相关产品推荐
相关产品推荐

