Solution To The Issue, “Git Command Is Taking Wrong User Name”

Yes, this was a strange scenario for me. I created Angular 2 project in Visual Studio code and wanted to push the project into a GitHub Repository. Sounds like a simple requirement right? Thus, to publish the project to a GitHub Repository, I ran the following five commands in the order, given below-

  1. git init
  2. git add –A
  3. git commit –m “commitmessage”
  4. git remote add origin “Url of GitHub Repo”
  5. git push rigin master

For the push command, I got the error, as shown in the image, given below-
command
Error message is very clear that the user djinfragistics does not have an access to the remote repository. Hence, HTTP Error code 403 is returned from the GitHub Server.

To check the current user name for the project, I ran the commands-

  1. git config user.name
  2. git config user.email

As shown in the image, given below, I found the username and user Email was set to the user, which had access to remote repository.

command

I was confused and was not able to figure it out. Due to this, git command is not taking the user from the current project and taking some random user djinfragistics. I thought, it might be the global user, which is set to djinfragistics. Thus, to check that, I ran the commands, given below-

  1. git config –global user.name
  2. git config –global user.email

As shown in the image below, I found the username and a user Email was set to the user, which had access to the remote repository.

command
It was strange, that the global user is also set to the different user, however to publish the project, git was taking some strange user djinfragistics from somewhere.

After a bit of research, I found that on Windows, when we install git 2. Credential Manager also gets installed. It runs as a daemon process and caches the git user credentials, such that each time, we do not have to provide the user information to push the changes to GitHub repository.

In my scenario, I might have used djinfragistics username earlier on the same system and that user got cached in Credential Manager. So even though user was set to debugmode, on running the command git was taking user djinfragistics from credential manager.

To check the various options, run the command, as shown below-

  • git credential-manager
    Above command will show us all the options of Credential Manager. I was lazy and wanted to publish the project, as early as possible, so I ran the command, given below- 

  • git credential-manager uninstall
    command
    The command shown above will uninstall Credential Manager and we will have to provide git user credentials each time. I would recommend you to explore various options and edit the file rather than uninstalling it.

It solved my problem and git command started taking the correct user name. I hope, it helps.

Up Next
    Ebook Download
    View all
    Learn
    View all