| domain | contrib |
|---|---|
| title | gh credential helper 路径Error导致 git push 静默失败 |
| verification | metadata-normalized |
| created | 2026-07-06 |
| source | unknown |
---{"title": "gh credential helper 路径Error导致 git push 静默失败", "domain": "devops", "tags": ["git", "github", "credential", "gh", "auth", "push"]}---
执行 git push 时卡住或报错:
/home/hp/.local/bin/gh auth git-credential get: 1: /home/hp/.local/bin/gh: not found
或:
remote: Repository not found.
fatal: repository 'https://github.com/...' not found
但其实仓库存在,token 也有效。
gh 安装在 /usr/bin/gh,但 git 全局配置中的 credential helper 指向了一个不存在的路径:
credential.https://github.com.helper=
credential.https://github.com.helper=!/home/hp/.local/bin/gh auth git-credential
^^^^^^^^^^^^^^^^^^
这个路径没有 gh 二进制
这通常是安装 gh 后又通过 git config --global credential.helper 自动配置的遗留项。当 WSL Ubuntu 通过 apt install gh 安装时,gh 在 /usr/bin/gh,但 credential helper 可能指向其他位置。
git config --global --list | grep credentialgit config --global --unset-all credential.https://github.com.helper
git config --global --unset-all credential.https://gist.github.com.helper# gh credential helper 路径Error导致 git push 静默失败
git config --global credential.helper store
# 确认 .git-credentials 里有有效 token
cat ~/.git-credentials
# 格式: https://username:TOKEN@github.comgit ls-remote origin HEAD
# 应正常返回 commit hash,不再报错修复后用以下命令确认 credential 链干净:
git config --global --list | grep helper
# 预期输出: credential.helper=store
# 不应出现 gh auth git-credential
# 测试 push
git push
# 应直接推送成功,不卡顿不报错- 新装
gh后用gh auth login登录后,检查 credential helper 是否引入了错误路径 - 如果同时使用
credential.helper store和gh auth git-credential,确保gh auth git-credential的路径与二进制位置一致 - 用
which gh确认真实路径,与 git config 中的 credential helper 路径对比
English:
lessons/en/git-credential-helper-gh-path-mismatch.md