You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio推送代码至GitHub失败,Git报致命错误求解决

Fixing "Failed to Push to Remote Repository" with Git Authentication Errors

Hey there, let's tackle this push failure you're facing—those error messages are pointing straight to an authentication issue where Git can't prompt you for your GitHub credentials. Here's a breakdown of the problem and step-by-step fixes:

What's Causing the Error?

The key lines in your error log tell the whole story:

cannot spawn askpass: No such file or directory
could not read Username for 'https://github.com': terminal prompts disabled

This means Git tried to request your GitHub username and access token (note: GitHub no longer accepts account passwords for pushes) but hit a wall. Either it couldn't find a tool to show a graphical prompt, or terminal prompts were disabled so it couldn't ask you directly. Without valid credentials, GitHub rejects the push outright.

Step-by-Step Fixes

Set up Git's credential helper to remember your GitHub personal access token (PAT) so you don't have to enter it every time:

  • Windows:
    git config --global credential.helper wincred
    
  • Mac:
    git config --global credential.helper osxkeychain
    
  • Linux (use cautiously on public machines):
    git config --global credential.helper store
    

After running this, try pushing again. The first time, you'll be prompted to enter your GitHub username and personal access token (generate one in GitHub's Settings > Developer Settings > Personal access tokens, with the repo permission enabled). Git will store these credentials securely for future pushes.

2. Switch to SSH for Remote Repository Access

SSH links eliminate the need for username/token prompts entirely (once your SSH key is set up on GitHub):

  1. Check your current remote URL:
    git remote -v
    
  2. If it starts with https://, replace it with the SSH format:
    git remote set-url origin git@github.com:YourUsername/YourRepositoryName.git
    

Make sure you've added your local SSH public key to your GitHub account (Settings > SSH and GPG keys) before trying this method.

3. Temporarily Enable Terminal Prompts (Quick Fix)

If you just need to push once right away, disable the askpass helper to force Git to prompt you directly in the terminal:

git config --global --unset core.askpass

Or set it to an empty value:

git config --global core.askpass ""

Then run your push command again—you'll see a prompt to enter your GitHub username and PAT to complete the push.

内容的提问来源于stack exchange,提问作者Antero00

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:00:30