What "Could Not Read Username" Means and Why It Happens
When Git shows "could not read username for https://github.com", it means your computer tried to connect to GitHub but couldn't find stored login information, or the information it found was corrupted or incomplete. This usually happens when you are pushing code, pulling updates, or cloning a repository over HTTPS — the encrypted web connection method.
The error appears because Git needs to know who you are before it can let GitHub know who is sending the code. Unlike SSH (a different connection method that uses a key file), HTTPS requires Git to retrieve your username and password or token from somewhere on your machine. If that stored information is missing, wrong, or unreadable, the connection fails before it even reaches GitHub.
The most common causes are: you have never set up credentials on this computer, your credentials file got corrupted or deleted, you switched to a new device, you are using a different user account on the same machine, or your stored password or token has expired.
Key Takeaways
- The error means Git cannot find your stored GitHub username and password or token on your computer, not that your GitHub account is broken.
- On Windows, credentials are stored in Credential Manager; on Mac and Linux, they are stored in a credentials file that Git creates the first time you log in.
- The fastest fix is to delete the old stored credentials and let Git prompt you to enter them fresh the next time you push or pull.
- If you use a personal access token instead of your password, make sure the token has not expired and has the right permissions for the repository you are accessing.
- Switching to SSH (using a key file instead of a password) prevents this error from happening again, though it requires one-time setup.
How to Clear and Reset Stored Credentials on Windows
On Windows, Git stores your GitHub credentials in Windows Credential Manager. The fastest fix is to delete the old entry and let Git create a new one the next time you need it.
Open Credential Manager by pressing the Windows key, typing "credential manager", and clicking "Credential Manager" in the results. Look for an entry that says "git:https://github.com" or just "github.com". Click it, then click "Remove". Close Credential Manager.
The next time you push, pull, or clone over HTTPS, Git will prompt you to enter your username and password (or token) in a pop-up window. Enter your GitHub username and your personal access token — not your GitHub password, since GitHub stopped accepting passwords for Git operations in 2021. If you do not have a token yet, you will need to create one on GitHub first.
How to Clear and Reset Stored Credentials on Mac and Linux
On Mac and Linux, Git stores credentials in a file called .git-credentials in your home directory. You can delete it or edit it directly from the terminal.
To delete it entirely, open Terminal and type: rm ~/.git-credentials. Press Enter. The next time you push or pull, Git will ask for your username and token in the terminal itself.
If you want to edit the file instead of deleting it, type: nano ~/.git-credentials. You will see entries in the format https://username:token@github.com. Delete the line for github.com, save the file (Ctrl+O, then Enter, then Ctrl+X), and close the editor. Again, Git will prompt you for fresh credentials on your next operation.
Entering a Personal Access Token Instead of Your Password
GitHub requires a personal access token instead of your account password when you use HTTPS from the command line. If you have been using your password and it stopped working, that is why.
To create a token, log into GitHub on the web, click your profile picture in the top right, select "Settings", then "Developer settings", then "Personal access tokens", then "Tokens (classic)". Click "Generate new token". Give it a name like "Git on my laptop", set an expiration date (90 days is common), and check the box for "repo" — this gives the token permission to read and write to your repositories. Click "Generate token" at the bottom. GitHub will show you the token once; copy it when ready and save it somewhere safe.
When Git prompts you for your password, paste this token instead. Do not use your actual GitHub password. If the token expires, you will see the "could not read username" error again, and you will need to create a new token and update your stored credentials.
Checking That Your Token Has the Right Permissions
If you have a token but Git still will not connect, the token may not have permission to access the repository you are trying to use. Tokens can be restricted to specific repositories or given broad access.
Log into GitHub, go to "Settings" > "Developer settings" > "Personal access tokens" > "Tokens (classic)", and click the token you are using. Check that the "repo" scope is checked — this is the permission that lets you push and pull code. If it is not checked, click "Edit", check "repo", and click "Update token".
Also check the expiration date. If it says "Expired", the token no longer works. Create a new one using the steps above, then update your stored credentials with the new token.
Switching to SSH to Avoid This Error Permanently
If you want to stop dealing with passwords and tokens altogether, you can use SSH instead of HTTPS. SSH uses a key file on your computer instead of a password, so Git never needs to ask for credentials.
To set this up, open Terminal (Mac/Linux) or Git Bash (Windows), and type: ssh-keygen -t ed25519 -C "your-email@example.com". Replace the email with the one you use for GitHub. Press Enter three times to accept the defaults. This creates a key file on your computer.
Then type: cat ~/.ssh/id_ed25519.pub (Mac/Linux) or type %userprofile%\.ssh\id_ed25519.pub (Windows in Git Bash). Copy the entire output. Log into GitHub, go to "Settings" > "SSH and GPG keys", click "New SSH key", paste the output, and click "Add SSH key".
From now on, when you clone a repository, use the SSH URL (it looks like git@github.com:username/repo.git) instead of the HTTPS URL. Git will use your key file automatically, and you will never see the "could not read username" error again.
What to Do If You Are Using a Different User Account on the Same Computer
If you switched to a different user account on your computer (or someone else is using the machine), they will not have access to your stored credentials. Each user account on a computer has its own separate credentials storage.
If you are the same person but logged in as a different user, you will need to enter your GitHub credentials again. Git will prompt you the next time you push or pull. If you are a different person entirely, you should enter your own GitHub username and token, not the previous user's.
If you are sharing a computer with others, consider using SSH keys instead of passwords or tokens. You can create a separate key for each person, and each key can be restricted to specific repositories.
Frequently Asked Questions
Why does Git ask for my password when I thought I already saved it?
Your saved credentials may have been deleted, corrupted, or expired. The stored information could also be unreadable if you changed your computer's user account password or if the credentials file got damaged. Clearing the old credentials and entering them fresh usually fixes this.
Can I use my GitHub password instead of a token?
No. GitHub stopped accepting passwords for Git operations in 2021. You must use a personal access token. If you try to use your password, Git will reject it and show an authentication error.
What if I forgot my personal access token?
GitHub does not show you a token after you create it, so if you lost it, you cannot retrieve it. You will need to create a new one. Go to "Settings" > "Developer settings" > "Personal access tokens" > "Tokens (classic)", and click "Generate new token". Copy it when ready and store it somewhere safe.
Does SSH work on Windows?
Yes. Windows 10 and later have built-in SSH support. You can also use Git Bash, which comes with Git for Windows and includes SSH. Follow the same SSH setup steps, and it will work the same way as on Mac or Linux.
Will clearing my credentials affect other programs that use GitHub?
Only programs that store credentials in the same place will be affected. If you use GitHub Desktop, VS Code, or other tools, they may store credentials separately. Clearing Git's credentials will not touch those. However, if those programs use Git under the hood, they may also prompt you to log in again.