Removing Stale Git HTTPS Credentials on Windows
Git authentication errors (such as remote: Failed to authenticate user or fatal: Authentication failed for ...) typically occur when Git Credential Manager (GCM) stores outdated, expired, or invalid credentials for a specific server (e.g., Gitea, GitHub, GitLab).
Below are verified methods for clearing cached HTTPS credentials in Windows and re-configuring repository access.
Method 1: Windows Credential Manager (GUI)
This is the simplest graphical method for editing or removing saved passwords and tokens.
- Press
Win + R, type the following command, and press Enter:
cmd control /name Microsoft.CredentialManager
(Alternatively, open the Start menu and search for Credential Manager). - Select Windows Credentials.
- Under Generic Credentials, find entries associated with your Git server, for example:
git:https://gitea.example.comgit:https://refresh_token.gitea.example.comgit:https://github.com- Expand the details of the entry and click Remove.
Method 2: Command Prompt / PowerShell (cmdkey)
A fast command-line approach using Command Prompt (CMD) or PowerShell.
1. Find Stale Git Credentials
cmdkey /list | findstr /i "git gitea github"
2. Remove Specific Credential
Pass the exact target name (Target) obtained from the previous command:
cmdkey /delete:git:https://gitea.example.com
Method 3: Git Credential Manager (CLI)
You can use Git's built-in credential management tool directly from your terminal.
Erase credentials for a specific host:
git credential-manager erase --host=gitea.example.com
Alternative (git credential helper interface):
(echo protocol=https & echo host=gitea.example.com) | git credential reject
Re-authenticating After Clearing
Once outdated credentials are removed, run a Git command from an interactive terminal:
git push
Authentication Notes:
[!IMPORTANT]
- Servers with Two-Factor Authentication (2FA): If 2FA is enabled on your Git server (Gitea / GitHub / GitLab) or password authentication is disabled for Git operations, you must use a Personal Access Token (PAT) instead of your account password.
- Generating a Token in Gitea: Navigate toUser Settings→Applications→Generate New Tokenand ensure repository permissions (reposcope) are selected.
Alternative: Switch Repository Remote to SSH
If you have an SSH key configured on your Git server, you can switch the remote repository URL from HTTPS to SSH to avoid issues with HTTPS passwords and tokens:
git remote set-url origin [email protected]:your-org/your-repo.git
git push