Introduction
Recently, I needed to switch my local Git environment from one Git hosting account to another. My original setup was configured for an older developer account, but I wanted to push code to a repository owned by a different account.
At first, the process seemed straightforward—just update the Git username and email. However, I encountered multiple authentication issues, including:
Logon failed errors
Credential Manager conflicts
GitHub 403 permission errors
Personal Access Token (PAT) permission problems
This article documents the troubleshooting process and the final solution that worked.
Initial Configuration
My local Git configuration was still pointing to my old account:
git config --global user.name
# old_username
git config --global user.email
# old_email@example.com
The target repository was a newly created repository under a different account.
Step 1: Update Local Git Identity
I updated the Git username and email to match the new Git hosting account:
git config --global user.name "new_username"
git config --global user.email "new_email@example.com"
Verification:
git config --global user.name
git config --global user.email
This successfully updated the commit author information for future commits.
However, pushing to the remote repository still failed.
Step 2: Verify the Remote Repository
I checked the repository remote URL:
git remote -v
Output:
origin https://github.com/new_username/project_repository.git (fetch)
origin https://github.com/new_username/project_repository.git (push)
The remote was already configured correctly.
Step 3: Investigate Authentication Failures
Attempting to push resulted in:
Logon failed, use ctrl+c to cancel basic credential prompt.
This suggested that Git was using cached credentials from a previous configuration.
I checked Git's credential configuration:
git config --list --show-origin | findstr credential
Output:
file:"C:\ProgramData\Git\config" credential.helper=manager
The culprit was Git Credential Manager.
Step 4: Remove Git Credential Manager
Opening:
C:\ProgramData\Git\config
revealed:
[credential]
helper = manager
I removed:
[credential]
helper = manager
and saved the file.
Verification:
git config --list --show-origin | findstr credential
Output:
credential.https://dev.azure.com.usehttppath=true
The Credential Manager entry was gone.
Step 5: Push Again
After removing the Credential Manager configuration, Git finally prompted for credentials:
Username for 'https://github.com':
I entered:
new_username
Then:
Password for 'https://new_username@github.com':
I entered a GitHub Personal Access Token (PAT).
Unfortunately, I still received:
remote: Permission denied
fatal: The requested URL returned error: 403
Step 6: Discover the Real Problem
The issue was not the repository.
The issue was the token.
Inspecting the token revealed:
Repository access:
This token does not have access to any repositories.
Repository permissions:
This token does not have any repository permissions.
The token could authenticate the account but could not authorize repository actions such as pushing commits.
Step 7: Create a Proper Personal Access Token
I generated a new token with repository permissions.
For fine-grained tokens, the important settings were:
Repository access:
All repositories
and
Contents:
Read and Write
Without "Contents: Read and Write," GitHub rejects push operations with a 403 error.
Step 8: Push Successfully
After generating a properly configured PAT, I executed:
git push -u origin main
Git prompted for:
Username:
new_username
Password:
<Personal Access Token>
The result:
Counting objects: 22, done.
Compressing objects: 100% (18/18), done.
Writing objects: 100% (22/22), done.
[new branch] main -> main
Branch main set up to track remote branch main from origin.
Success.
The repository was successfully pushed under the new account.
Important Lesson: Git Identity vs GitHub Authentication
One of the biggest takeaways from this process is understanding the difference between:
Git Identity
git config --global user.name
git config --global user.email
These values determine:
Commit author
Commit email
How commits appear in Git history
GitHub Authentication
Username + Personal Access Token
These determine:
Which account is authenticated
Which repositories can be accessed
Whether pushes are authorized
Changing the Git identity does not automatically change GitHub authentication.
Final Thoughts
Switching GitHub accounts on a local machine can involve more than changing a username and email. Credential managers, cached authentication data, and token permissions can all introduce unexpected issues.
The solution ultimately required:
Updating Git identity
Verifying the remote repository
Removing Git Credential Manager configuration
Creating a PAT with correct repository permissions
Authenticating using the new account
Once these steps were completed, pushing to the remote repository worked as expected.
Hopefully, this walkthrough helps other developers avoid the same troubleshooting process and better understand the distinction between Git configuration and repository authorization.