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 a simple requirement right? So to publish the project to a GitHub Repository, I ran following 5 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 origin master

For the push command, I got the error as shown in the image below. Focus on error message for user djinfragistics

image

Error message is very clear that user djinfragistics does not have access to the remote repository hence HTTP Error code 403 is returned from the GitHub server.

To check current user name for the project I ran the command

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

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

image

I was confused and was not able to figure it out that why git command is not taking user from the current project and taking some random user djinfragistics. I thought might be global user is set to djinfragistics. So, to check that I ran the command as below

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

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

image

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

After bit of researching, 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 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 various options, run the command as shown below

  • git credential-manager

Above command will show us all options of credential manager. I was lazy and wanted to publish project as early as possible, so I ran

  • git credential-manager uninstall

image

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

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

Advertisements

One thought on “Git command is taking wrong user? To solve – check CredentialManager

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s