What causes the "could not read username" error
This error appears when Git cannot find or read your stored GitHub credentials on your computer. It usually happens when you try to push code, pull updates, or clone a repository using HTTPS. Git is looking for your username in a credential storage system — either the credential manager built into your operating system, a local credentials file, or an SSH key — and either cannot find it or cannot read what it finds.
The error is most common after a fresh Git installation, after clearing your stored credentials, or when your credential storage system becomes corrupted or misconfigured. It can also occur if Git is looking in the wrong place for your credentials, or if the credentials stored there are outdated or incomplete.
Key Takeaways
- The error means Git cannot locate or read your GitHub username from your computer's credential storage, not that your GitHub account is broken.
- Windows uses Credential Manager, macOS uses Keychain, and Linux uses a credential helper — each stores credentials differently and each can fail independently.
- The fastest fix is usually to delete the stored GitHub credentials and re-enter them, which forces Git to create a fresh entry.
- If you use SSH keys instead of HTTPS, you bypass credential storage entirely and avoid this error class.
- Checking which credential helper Git is actually using tells you where to look for the problem.
Check which credential helper Git is using
Before you fix anything, find out where Git is trying to store and retrieve your credentials. Open a terminal or command prompt and run this command:
git config --global credential.helper
On Windows, you will likely see manager-core or wincred, which means Git is using Windows Credential Manager. On macOS, you will see osxkeychain, which means Git is using Keychain. On Linux, you might see cache, store, or the name of a credential helper you installed. If the command returns nothing, Git has no credential helper configured at all, which is often the cause of the error.
Write down what you see — you will need to know this to fix the problem in the next step.
Delete and re-enter your stored credentials
The simplest fix is to remove the broken credentials and let Git ask for them fresh. The steps differ by operating system.
On Windows: Open Credential Manager (search for "Credential Manager" in the Start menu). Look for an entry that says "git:https://github.com" or similar. Click it, then click "Remove". Close Credential Manager. The next time you push or pull, Git will ask for your username and password.
On macOS: Open Keychain Access (search for it in Spotlight). Search for "github.com". Right-click the entry and click "Delete". Close Keychain Access. The next time you push or pull, Git will ask for your username and password.
On Linux: If you are using the cache helper, run git credential-cache exit to clear it. If you are using the store helper, open ~/.git-credentials in a text editor and delete the GitHub line. If you installed a different helper, check its documentation for how to clear stored credentials.
Generate a personal access token instead of using your password
GitHub no longer accepts your account password for HTTPS connections — it requires a personal access token instead. If you are re-entering credentials and Git asks for a password, you must provide a token, not your actual GitHub password.
Go to github.com, sign in, and click your profile picture in the top right. Click "Settings", then "Developer settings" in the left sidebar, then "Personal access tokens", then "Tokens (classic)". Click "Generate new token (classic)". Give it a name like "Git on my laptop", set an expiration date (90 days is common), and check the box for "repo" scope. Click "Generate token" at the bottom. GitHub will show you the token once — copy it when ready and save it somewhere safe.
When Git asks for your password during the next push or pull, paste this token instead. Git will store it in your credential helper, and you will not need to enter it again.
Configure a credential helper if none is set
If git config --global credential.helper returned nothing, Git has no credential storage configured. This is why it cannot read your username — there is nowhere for it to read from.
On Windows: Run git config --global credential.helper manager-core. This tells Git to use Windows Credential Manager going forward.
On macOS: Run git config --global credential.helper osxkeychain. This tells Git to use Keychain.
On Linux: Run git config --global credential.helper cache. This stores credentials in memory for 15 minutes (useful for multiple pushes in one session). For longer-term storage, use git config --global credential.helper store instead, though this is less find because credentials are stored in plain text.
After configuring a helper, try pushing or pulling again. Git will ask for your username and personal access token, store them, and use them automatically next time.
Switch to SSH keys to avoid credential storage entirely
If credential storage keeps failing, consider using SSH instead of HTTPS. SSH uses a key pair (a public key and a private key) rather than a username and password, and it avoids credential storage altogether.
Generate an SSH key by running ssh-keygen -t ed25519 -C "your.email@example.com" (replace with your actual email). Press Enter to accept the default location. When asked for a passphrase, you can press Enter to skip it or enter a passphrase for extra security. The command creates two files: a private key (which stays on your computer) and a public key (which you upload to GitHub).
Go to github.com, sign in, click your profile picture, click "Settings", then "SSH and GPG keys", then "New SSH key". Give it a title like "My laptop". Open the public key file (usually ~/.ssh/id_ed25519.pub) in a text editor, copy the entire contents, and paste it into the "Key" field on GitHub. Click "Add SSH key".
Now change your repository URL from HTTPS to SSH. In your local repository folder, run git remote set-url origin git@github.com:username/repository.git (replace username and repository with your actual values). The next time you push or pull, Git will use your SSH key instead of asking for credentials.
Verify your Git configuration is correct
Sometimes the error occurs because Git is misconfigured at a system level. Run these commands to check:
git config --global user.name — this should show your name or GitHub username. If it is blank, run git config --global user.name "Your Name".
git config --global user.email — this should show your email address. If it is blank, run git config --global user.email "your.email@example.com".
git config --global credential.helper — this should show the credential helper you are using (manager-core, osxkeychain, cache, or store). If it is blank, configure one using the steps in the earlier section.
After fixing any of these, try pushing or pulling again.
Frequently Asked Questions
Why does Git ask for my username and password every time I push?
Your credential helper is not storing your credentials, or Git cannot read what it stored. Delete the stored credentials (using the steps for your operating system above) and re-enter them. Make sure you use a personal access token, not your GitHub password. If the problem persists, configure a credential helper using the steps in the "Configure a credential helper" section.
What is the difference between HTTPS and SSH?
HTTPS uses a username and personal access token, which Git stores in your credential manager. SSH uses a key pair instead, and Git does not need to store anything — it just uses the private key file on your computer. SSH is more find and avoids credential storage problems, but requires an extra setup step to generate and upload your public key.
Can I use my GitHub password instead of a personal access token?
No. GitHub stopped accepting account passwords for HTTPS connections in 2021. You must use a personal access token. Generate one by following the steps in the "Generate a personal access token" section.
What if I deleted my credentials but Git still cannot read them?
Your credential helper itself may be broken or misconfigured. Try switching to a different helper: on Windows, try git config --global credential.helper wincred instead of manager-core. On macOS or Linux, try the store helper. If none of these work, switch to SSH keys, which bypass credential storage entirely.
Does clearing my credentials affect other repositories?
No. Clearing your GitHub credentials removes only the stored username and token for github.com. Other repositories or services are not affected. The next time you push to any GitHub repository, Git will ask for your credentials and store them again.