If you've recently tried to push code to a private GitHub repository using HTTPS and encountered an error like this:
fatal: HttpRequestException encountered.
An error occurred while sending the request.
Username for 'https://github.com': abcd
remote: Support for password authentication was removed on August 13, 2021.
fatal: Authentication failed for 'https://github.com/test/cr/
Don't panic โ you're not alone. This blog will explain why and how to fix it using GitHub's current authentication methods.
โ Why This Happens
Since August 13, 2021, GitHub no longer supports password-based authentication for Git operations over HTTPS.
This change was made to improve security, and now developers must authenticate using either:
๐ Personal Access Tokens (PAT)
๐ก๏ธ SSH Keys
โ Solution 1: Use a Personal Access Token (HTTPS)
When Git prompts for a username and password, you should:
Enter your GitHub username as usual
Enter your Personal Access Token instead of your password
๐ง Steps to Create a Token:
Go to GitHub โ Settings โ Developer Settings โ Personal Access Tokens
Click โGenerate new token (classic)โ or โFine-grained tokenโ
Set expiration (e.g., 30 days)
Select the **repo **scope
Click Generate token
Copy the token *immediately *(you won't see it again)
๐จโ๐ป Next, push your code:
git add .
git commit -m "Your commit message"
git push origin your-branch-name
When prompted:
Username:<Enter Your Github Username>
Password: Paste the token you generated
โ Solution 2: Use SSH (Recommended for Long-Term)
If you regularly work with private repos, SSH is more convenient and secure.
๐ง Steps:
- Generate SSH Key:
ssh-keygen -t ed25519 -C "[email protected]"
- Add SSH Key to GitHub:
Copy the public key:
cat ~/.ssh/id_ed25519.pub
Then go to GitHub โ Settings โ SSH and GPG Keys
โ Click โNew SSH Keyโ, paste the key, and save.
- Switch your remote URL:
git remote set-url origin [email protected]:OUP2/ernie.git
- Now push:
git push origin your-branch-name
๐ง Bonus: Cache Your Credentials (Optional)
To avoid typing your token repeatedly:
git config --global credential.helper cache
Or use GitHubโs credential manager for Windows/macOS.
๐ You're Good to Go!
By replacing your GitHub password with a PAT or SSH key, you'll be compliant with GitHubโs current security policies and avoid annoying errors like HttpRequestException encountered
.
Happy coding! ๐ปโจ
Top comments (0)