Git Bash still pushes repo with old Username

So, I am attempting to push my github repository to github. However, I changed usernames a little while back, and it still thinks that I am pushing with my old username. I have tried the following commands.

git config --global user.name
CorrectUsername

git config --global user.email
CorrectEmail@correctdomain

git config --unset --global user.name

git config --unset --global user.email

git config --unset user.name

git config --unset user.email

git remote rm origin

git remote set-url origin https://github.com/CorrectUsername/CorrectRepo

git config user.name "CorrectUsername"

git config user.email "CorrectEmail"

git config --global user.name "CorrectUsername"

git config --global user.email "CorrectUsername@correctdomain"

git config --list

After this, I still obtain a 403 error saying that my old username failed to push the repo:

git push origin master

remote: Permission to CorrectUsername/CorrectRepo.git denied to OldUsername.
fatal: unable to access 'https://github.com/rogerskev17/KnightQuest/': The requested URL
returned error: 403

How can I get Github to use the new username that I put in?

3 Likes

What do you see when you are in your repo that gives you the error and you type the following command?

git config --list | grep user.name

I have the same problem

Using that following command returns new username but it still remember old username somehow

1 Like

Did u find the solution, i also having the same problem

Same problem here. Is there any solition?

Solution 1.

Locally:

git config credential.username "new_username"

Globally:

git config --global credential.username  "new_username"

Solution 2. (In case solution 1 doesn’t work):

git remote set-url origin "https://new_username@github.com/new_username/github-repository-name.git" 
6 Likes

Thank you so much…you saved my day.

1 Like

After all these suggestions I still can’t commit to my own repo’s with my new account, still shows my old account as the contributor T.T

Really thanks. It worked for me.

did you try uninstalling git bash? and restarting the computer?

I solved this by going to my Windows’s Credential Manager and delete the old github credentials stored on computer. You can try and see if it works.

1 Like

this solution worked for me