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

Git克隆GitHub仓库失败求助:终端提示禁用无法读取用户名

Fixing the "fatal: could not read Username for 'https://github.com'" Git Cloning Error

Hey there, let’s work through this Git issue step by step—this is a super common snag for folks new to GitHub, so don’t stress! The error happens because Git can’t prompt you for your GitHub credentials (thanks to disabled terminal prompts) and can’t find the askpass tool that usually handles credential pop-ups. Here are four solid fixes, ordered from quick temp fixes to long-term solutions:

1. Clone with Credentials Embedded in the URL (Quick Temporary Fix)

If you just need to get the repo cloned right now, you can plug your GitHub username and personal access token directly into the HTTPS URL:

git clone https://<YOUR_GITHUB_USERNAME>:<YOUR_PERSONAL_ACCESS_TOKEN>@github.com/<USERNAME>/<REPO_NAME>.git
  • Note: You’ll need to generate a personal access token first in your GitHub settings (Settings → Developer settings → Personal access tokens) — make sure to check the repo permission box. Skip this method on public computers, since it exposes your token in plain text.

2. Set Up a Git Credential Helper (Long-Term HTTPS Fix)

This lets Git save your credentials so you don’t have to enter them every time:

  • Run the appropriate command for your OS to set a global credential helper:
    # Windows
    git config --global credential.helper wincred
    
    # macOS
    git config --global credential.helper osxkeychain
    
    # Linux (stores credentials in plain text at ~/.git-credentials — use cautiously)
    git config --global credential.helper store
    
  • After running this, try cloning the repo again. You’ll get a prompt to enter your username and token, and Git will remember them for future operations.

3. Reset Git’s Prompt and Askpass Settings

Sometimes Git’s config gets messed up, disabling terminal prompts or pointing to a missing askpass tool. Fix that with these commands:

git config --global --unset core.askpass
git config --global core.prompt true

Now try cloning again—Git should prompt you directly in the terminal for your username and token.

SSH avoids credential prompts entirely once set up, and it’s more secure than HTTPS for regular use:

  1. Generate an SSH key pair on your new computer:
    ssh-keygen -t ed25519 -C "your-github-email@example.com"
    
  2. Copy the public key (found at ~/.ssh/id_ed25519.pub on macOS/Linux, or C:\Users\<YOUR_USER>\.ssh\id_ed25519.pub on Windows) and add it to your GitHub account: Go to Settings → SSH and GPG keys → New SSH key, paste the key, and save.
  3. Clone the repo using the SSH URL instead of HTTPS:
    git clone git@github.com:<USERNAME>/<REPO_NAME>.git
    

From now on, Git will use your SSH key to authenticate, no more credential prompts!


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:37:18