Error 403 when pushing to GitHub repository: Need to change Git username associated with repository

73 views Asked by At

I am facing an issue while trying to push changes to my GitHub repository. The error message I'm encountering is as follows:

remote: Permission to mehdiergaibi/stock-managment.git denied to Mehdi-Ergaibi.
fatal: unable to access 'https://github.com/mehdiergaibi/stock-managment.git/': The requested URL returned error: 403

Upon investigation, I realized that the username associated with the repository is set to my older account (Mehdi-Ergaibi), which I'm not actively using. In my Git configuration, the correct username for my new GitHub account is set to mehdiergaibi.

How can I change the Git username associated with this repository to ensure that it uses the correct username (mehdiergaibi) instead of the old one (Mehdi-Ergaibi)? Any guidance on resolving this issue would be greatly appreciated. Thank you!

1

There are 1 answers

3
ouuan On

If you still have access to the old account, you can transfer the ownership of the GitHub repository to the new account in the repository settings. In this way, you can keep not only the codes and commit history but also other things like issues and pull requests. After the transfer, you can use git remote set-url origin <new url> to change the local config.

Otherwise, you can create a new empty repository at https://github.com/new, use git remote set-url origin <new url> to change the local config, and then use git push -u origin <master or main> to push current codes to the new GitHub repository.